package kr.co.pension.usr.pe.re.controller;

import java.awt.Image;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;

import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.ImageIcon;

import kr.co.kiso.usr.utils.ConstValue;
import kr.co.kiso.usr.utils.SEEDUtil;
import kr.co.pension.admin.co.ma.service.COMAService;
import kr.co.pension.admin.co.ma.vo.COMAVo;
import kr.co.pension.admin.pe.ti.service.PETIService;
import kr.co.pension.admin.pe.ti.vo.PETIVo;
import kr.co.pension.usr.pe.re.service.PEREService;
import kr.co.pension.usr.pe.re.vo.PEREVo;
import kr.co.pension.utils.BaseController;
import kr.co.pension.utils.JspUtil;
import kr.co.pension.utils.MailUtil;
import kr.co.pension.utils.PaginationInfo;
import kr.co.pension.utils.SMCommonUtil;
import kr.co.pension.utils.sms.SMSUtil;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;

/**
 * 펜션 예약관리
 * @author devhw
 *
 */
@Controller
@RequestMapping("/usr/pe/re/*")
public class PEREController extends BaseController{
	@Autowired
	private PEREService service;
	
	@Autowired
	private PETIService petiService;
	
	@Autowired
	private COMAService comaService;

	Logger log = Logger.getLogger(getClass());
	

	/**
	 * 펜션 예약화면
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere100Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmDatedd = new SimpleDateFormat("dd");
		SimpleDateFormat frmDate1 = new SimpleDateFormat("yyyyMM");
		
		Calendar d1 = Calendar.getInstance();
		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int chkMonth = Integer.parseInt( frmDate1.format(d1.getTime().getTime()));
		int chkConditionMonth = Integer.parseInt( vo.getReservation_dt().substring(0,6));
		
		//이전달 조회 금지
		if(chkMonth>chkConditionMonth){
			vo.setReservation_dt(frmDate.format(d1.getTime()));
			chkConditionMonth = chkMonth;
			mav.addObject("msg", "이전달은 예약이 불가능합니다.");
		}

		Map pensionInfo = petiService.peti300Q(petiVo);
		String p_ico_yn = (String) pensionInfo.get("p_ico_yn");
		String p_id = (String) pensionInfo.get("p_id");
		String friday_yn = (String) pensionInfo.get("friday_yn");
		
		

		
		//설정한 달 이상 조회금지
		int reservation_use_month = (Integer) pensionInfo.get("reservation_use_month");
		if(reservation_use_month==0){
			reservation_use_month=13;	//예약 최대기간 1년1개월
		}
		reservation_use_month=reservation_use_month;
		Calendar maxMonthChk = Calendar.getInstance();
		maxMonthChk.add(Calendar.MONTH, reservation_use_month);
		int maxMonthNum = Integer.parseInt( frmDate1.format(maxMonthChk.getTime().getTime()));
		if(chkConditionMonth > maxMonthNum){
			vo.setReservation_dt(maxMonthNum+"01");
			chkConditionMonth = maxMonthNum;
			mav.addObject("msg", (reservation_use_month)+"개월 이상은 예약이 불가능합니다.");

		}
		int maxMonthNumDay = Integer.parseInt( Integer.toString(maxMonthNum) + frmDatedd.format(maxMonthChk.getInstance().getTime().getTime()));
		mav.addObject("reservation_dt", vo.getReservation_dt());
		
		SimpleDateFormat frmDateDD = new SimpleDateFormat("d");
		
		
		//객실 정보
		List list = service.pere101Q(vo);

		//요금 정보 및 예약정보
		ModelAndView retMv1 =  pere200_2Q(vo,req,res);
		List list2 = (List) ((Map) retMv1.getModel().get("map")).get("list");

		StringBuffer textCal = new StringBuffer();
		
		
		//달력 설정하는 부분
		Calendar drawCal = Calendar.getInstance();
		int sMonthWeek=0;
		int addDate=0;

		//일반달력일때

		if("D".equals(pensionInfo.get("reservation_cal") ) || chkMonth != chkConditionMonth){
			int year = Integer.parseInt(vo.getReservation_dt().substring(0,4));
			int month=Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
			int date=1;

			
			Calendar cal = Calendar.getInstance();
			cal.set(year, month, date);
			//지금 요일
			int day1_7 = cal.get(Calendar.DAY_OF_WEEK);
			
			//지금 몇번째 주
			int nowWeek =cal.get(Calendar.DAY_OF_MONTH);
			
			cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
			
			
			//이번달 몇번째주
			sMonthWeek =cal.get(Calendar.WEEK_OF_MONTH); 
			
			cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
			
			cal.get(Calendar.WEEK_OF_YEAR);

			
			int LastDate = cal.getActualMaximum(Calendar.DATE);

			addDate = (day1_7+6)-7;
			
			
			drawCal.set(year, month, date);
			drawCal.add(Calendar.DATE, -addDate);
			textCal.append("<tr class=\"tt\" align=\"center\">");
			for(int i=0;i<addDate ;i ++){
				String yyymmdd = frmDate.format(drawCal.getTime().getTime());
				String dd = frmDateDD.format(drawCal.getTime().getTime());
				textCal.append("<td class=\"day2\" bgColor=\"#f8f6f7\" vAlign=\"top\" width=\"14%\">&nbsp;&nbsp;&nbsp;</td>");
				drawCal.add(Calendar.DATE, 1);
			}
		}else{
			//이월달력일때
			Calendar cal = Calendar.getInstance();
			
			//지금 요일
			int day1_7 = cal.get(Calendar.DAY_OF_WEEK);
			
			//지금 몇번째 주
			int nowWeek =cal.get(Calendar.DAY_OF_MONTH);
			
			cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
			
			
			//이번달 몇번째주
			sMonthWeek =cal.get(Calendar.WEEK_OF_MONTH); 
			
			cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
			
			cal.get(Calendar.WEEK_OF_YEAR);

			
			int LastDate = cal.getActualMaximum(Calendar.DATE);

			addDate = (day1_7+6)-7;
			
//				Calendar drawCal = Calendar.getInstance();
			drawCal.add(Calendar.DATE, -addDate);
			textCal.append("<tr class=\"tt\" align=\"center\">");
			for(int i=0;i<addDate ;i ++){
				String yyymmdd = frmDate.format(drawCal.getTime().getTime());
				String dd = frmDateDD.format(drawCal.getTime().getTime());
				textCal.append("<td class=\"day2\" bgColor=\"#f8f6f7\" vAlign=\"top\" width=\"14%\">&nbsp;&nbsp;&nbsp;</td>");
				drawCal.add(Calendar.DATE, 1);
			}

			drawCal = Calendar.getInstance();
		}
		
		
		int chkWeek = 1;
		StringBuffer roomsList = new StringBuffer();
		StringBuffer tdHtml = new StringBuffer();
		int readFast = 0;
		for(int i=1;i<200 ;i ++){
			//초기화
			tdHtml.setLength(0);
			int startDate = addDate+i;
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			if(0!=i && "1".equals(dd)){
				dd=Integer.toString( Integer.parseInt(yyymmdd.substring(4,6))) +"."+dd;
			}
			String gl_busy_type="";
			String gl_pm_dc="";
			String gl_pm_dc_style="";
			
//			if("20120622".equals(yyymmdd)){
//				System.out.println("test");
//			}
			
			if(Integer.parseInt(frmDate.format(d1.getTime().getTime()))- Integer.parseInt(frmDate.format(drawCal.getTime().getTime()))>0){
				
				tdHtml.append("<td class=\"day23\" width=\"14%\" valign=\"top\" bgcolor=\"#fdfdf6\"");
				tdHtml.append("	id=\"day_"+yyymmdd+"\">");
				tdHtml.append("	<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">");
				tdHtml.append("		<tbody>");
				tdHtml.append("			<tr>");
				tdHtml.append("				<td align=\"left\" valign=\"top\" height=\"100\"><b><a href=\"#\">");
				tdHtml.append("					<font color=\"green\">"+dd+"</font></a></b>");
				tdHtml.append("					<span class=\"pm_nm pms\"></span>");
				tdHtml.append("					<span class=\"pm_dc pms\" style=\"color: red; text-align: center; position: relative; float: left; width: 100%; clear: both;\"></span>");
				textCal.append(tdHtml.toString() );
				textCal.append("				</td>");
				textCal.append("			</tr>");
				textCal.append("		</tbody>");
				textCal.append("	</table>");
				textCal.append("</td>");
				
				if(startDate % 7==0){
					textCal.append("</tr>");
					if(sMonthWeek==chkWeek){
						break;
					}
					textCal.append("<tr class=\"tt\" align=\"center\">");
					chkWeek++;
				}
				drawCal.add(Calendar.DATE, 1);
				
				
				continue;
			}
			String nowBgColor="@bgcolor";
			if(Integer.parseInt(frmDate.format(d1.getTime().getTime()))- Integer.parseInt(frmDate.format(drawCal.getTime().getTime()))==0){
				nowBgColor="#e3fefe";
			}
			
			tdHtml.append("<td class=\"day23\" width=\"14%\" valign=\"top\" bgcolor=\""+nowBgColor+"\"");
			tdHtml.append("	id=\"day_"+yyymmdd+"\">");
			tdHtml.append("	<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">");
			tdHtml.append("		<tbody>");
			tdHtml.append("			<tr>");
			tdHtml.append("				<td align=\"left\" valign=\"top\" height=\"100\"><b><a href=\"#\">");
			tdHtml.append("					<font color=\"green\">"+dd+"</font></a></b>");
			tdHtml.append("					<span class=\"pm_nm pms\">@pm_nm&nbsp;</span>");
			tdHtml.append("					<span class=\"pm_dc pms\" style=\"color: red; text-align: center; position: relative; float: left; width: 100%; clear: both;@pm_dc_style\">@pm_dc1&nbsp;</span>");
			
			String for_busy_type = "";
			int reservation_cnt =0; //예약수
			for(int j =0; j< list.size();j++){
				
				Map room = (Map) list.get(j);
				int pr_no = (Integer) room.get("pr_no");
				String room_nm = (String) room.get("room_nm");
				String room_type = (String) room.get("room_type");
				String room_form = (String) room.get("room_form");
				
				int busy_1_base  =   (Integer) room.get("busy_1_base");
				int busy_1_fri   =   (Integer) room.get("busy_1_fri");
				int busy_1_sat	=	(Integer) room.get("busy_1_sat");	
				
				roomsList.setLength(0);
				
				for(int k=readFast; k < list2.size();k++){
//						k=readFast;
					Map dateList = (Map) list2.get(k);
					
					String reservation_dt =  dateList.get("reservation_dt")==null?"":(String)dateList.get("reservation_dt");
					int rd_pr_no = (Integer) dateList.get("pr_no");
					
					if(Integer.parseInt(yyymmdd)< Integer.parseInt(reservation_dt)){
						
						readFast=k-list.size();
						if(readFast<0){
							readFast=0;
						}
						break;
					}
					if(reservation_dt.equals(yyymmdd) && pr_no == rd_pr_no){
						String busy_type = (String) dateList.get("busy_type")==null?"":(String)dateList.get("busy_type");
						for_busy_type = busy_type;
						String rm_status = (String) dateList.get("rm_status")==null?"":(String)dateList.get("rm_status");
						String reservation_nm = (String) dateList.get("reservation_nm")==null?"":(String)dateList.get("reservation_nm");
						String r_phone1 = (String) dateList.get("r_phone1")==null?"":(String)dateList.get("r_phone1");
						String r_phone2 = (String) dateList.get("r_phone2")==null?"":(String)dateList.get("r_phone2");
						String r_phone3 = (String) dateList.get("r_phone3")==null?"":(String)dateList.get("r_phone3");
						int pm_dc_m =  dateList.get("pm_dc_m")==null?0:(Integer)dateList.get("pm_dc_m");
						int pm_per =  dateList.get("pm_per")==null?0:(Integer)dateList.get("pm_per");
						
						String pm_pay = dateList.get("pm_pay")==null?"":String.valueOf(dateList.get("pm_pay")) ;
						gl_pm_dc_style="margin-top:-10px;";
						if("".equals(gl_pm_dc) ){
//							if("Y".equals(pensionInfo.get("pm_dc_yn")) ){
//								if("Y".equals(pensionInfo.get("pm_nm_yn")) ){
//									gl_pm_dc+="<br/>";
//								}
//							}
							gl_pm_dc+="<br/>";
							if(!"".equals(pm_pay) && "Y".equals(pensionInfo.get("pm_dc_yn"))){
								if(pm_dc_m>0){
									gl_pm_dc+="("+"DC : "+pm_dc_m+"원할인)";
								}
								if(pm_per>0){
									gl_pm_dc+="("+"DC : "+pm_per+"% 할인)";
								}
							}	
						}
						
						if("0101".equals(busy_type)){
							gl_busy_type="비수기 주중";
						}else if("0102".equals(busy_type)){
							gl_busy_type="비수기 금요일";
						}else if("0103".equals(busy_type)){
							gl_busy_type="비수기 토요일";
						}else if("0104".equals(busy_type)){
							gl_busy_type="준수기 주중";
						}else if("0105".equals(busy_type)){
							gl_busy_type="준수기 금요일";
						}else if("0106".equals(busy_type)){
							gl_busy_type="준수기 토요일";
						}else if("0107".equals(busy_type)){
							gl_busy_type="성수기 주중";
						}else if("0108".equals(busy_type)){
							gl_busy_type="성수기 금요일";
						}else if("0109".equals(busy_type)){
							gl_busy_type="성수기 토요일";
						}else if("0110".equals(busy_type)){
							gl_busy_type="휴일";
						}else{
							
							if(7==drawCal.get(Calendar.DAY_OF_WEEK)){//토요일
								gl_busy_type="비수기 토요일";
								busy_type = "0103";
							}else	if(6==drawCal.get(Calendar.DAY_OF_WEEK)
									&& "Y".equals(friday_yn)		//금요일 사용 함일경우
									){//금요일
								gl_busy_type="비수기 금요일";
								busy_type = "0102";
							}else{//평일
								gl_busy_type="비수기 주중";
								busy_type = "0101";
							}	
						}
						if("N".equals(pensionInfo.get("pm_nm_yn")) ){
							gl_busy_type="";
						}
						
						if("0110".equals(busy_type)){
							roomsList.append(" ");
						}else{
							roomsList.append("					<span	class=\"divDel\"><br/>");
							if("Y".equals(p_ico_yn)){
								if("F".equals(room_type)){
									roomsList.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");	
								}else if("C".equals(room_type)){
									roomsList.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								}else if("B".equals(room_type)){
									roomsList.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								}
							}
							String viewNm = room_nm;
							if("C".equals(rm_status)){
								viewNm="<span class=\"ptrend\">예약완료</span>";
								reservation_cnt++;
							}else if("R".equals(rm_status)){
								viewNm="<span class=\"ptrstandby\">예약대기</span>";
								reservation_cnt++;
							}
							String r_phone="";
							if(null != r_phone1 && !"".equals(r_phone1)){
								r_phone=r_phone1+"-"+r_phone2+"-"+r_phone3;
							}
							
							roomsList.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
							roomsList.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
							roomsList.append("							onmouseout=\"hideTip()\"> ");
							roomsList.append("							<a href=\"#\" id=\"a_"+pr_no+"_"+yyymmdd+"\"");
							roomsList.append("								onclick=\"goReserrvation('"+p_id+"',this,'"+pr_no+"');\" room_nm=\" "+room_nm+"\"");
							roomsList.append("								room_form=\""+room_form+"\" room_type=\""+room_type+"\" rm_status=\""+rm_status+"\" date=\""+yyymmdd+"\"");
							roomsList.append("								busy_1_base=\""+busy_1_base+"\" busy_1_fri=\""+busy_1_fri+"\" busy_1_sat=\""+busy_1_sat+"\" ");
							if(!"".equals(reservation_nm)){
								roomsList.append("								reservation_nm=\""+reservation_nm+"\" r_phone=\""+r_phone+"\" ");	
							}

							if(!"".equals(pm_pay)){
								roomsList.append("						pm_pay=\""+pm_pay+"\"");	
							}
							
							roomsList.append("								busy_type=\""+busy_type+"\"> "+viewNm+"</a>");
							roomsList.append("						</span>");
							roomsList.append("					</span>");
						}
						
						
					}
				}
//					설정 안되어있을경우 기본으로 설정합
				if("".equals(roomsList.toString()) ){
					//요금 설정해야함. 
					String busy_type = "";
					
					if(7==drawCal.get(Calendar.DAY_OF_WEEK)){//토요일
						gl_busy_type="비수기 토요일";
						busy_type = "0103";
					}else	if(6==drawCal.get(Calendar.DAY_OF_WEEK)
							&& "Y".equals(friday_yn)		//금요일 사용 함일경우
							){//금요일
						gl_busy_type="비수기 금요일";
						busy_type = "0102";
					}else{//평일
						gl_busy_type="비수기 주중";
						busy_type = "0101";
					}					
					if("N".equals(pensionInfo.get("pm_nm_yn")) ){
						gl_busy_type="";
					}
					
					//기본값 설정
					roomsList.append("					<span	class=\"divDel\"><br/>");
					if("Y".equals(p_ico_yn)){
						if("F".equals(room_type)){
							roomsList.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");	
						}else if("C".equals(room_type)){
							roomsList.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						}else if("B".equals(room_type)){
							roomsList.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						}
					}
					roomsList.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
					roomsList.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
					roomsList.append("							onmouseout=\"hideTip()\"> ");
					roomsList.append("							<a href=\"#\" id=\"a_"+pr_no+"_"+yyymmdd+"\"");
					roomsList.append("								onclick=\"goReserrvation('"+p_id+"',this,'"+pr_no+"');\" room_nm=\" "+room_nm+"\"");
					roomsList.append("								room_form=\""+room_form+"\" room_type=\""+room_type+"\" rm_status=\"\" date=\""+yyymmdd+"\"");
					roomsList.append("								busy_1_base=\""+busy_1_base+"\" busy_1_fri=\""+busy_1_fri+"\" busy_1_sat=\""+busy_1_sat+"\" ");
					roomsList.append("								busy_type=\""+busy_type+"\"> "+room_nm+"</a>");
					roomsList.append("						</span>");
					roomsList.append("					</span>");
				}else{
					
				}
				//휴일일 경우 객실정보 입력안함
				if(!"0110".equals(for_busy_type)){
					
					if(Integer.parseInt(yyymmdd) > maxMonthNumDay){
						roomsList.setLength(0);
						if(j==0){
							roomsList.append("<br/><br/>"+reservation_use_month+"개월 이상 예약불가");	
						}
						
					}
					tdHtml.append(roomsList.toString());
				}
//				tdHtml.append(roomsList.toString());
			}
			//휴일일경우 이미지로 대체
			if("0110".equals(for_busy_type)){
				tdHtml.append("<br/><table style=\"width:100%;height:100%;text-align: center\"><tr><td valign='middle'><img src=\"/usr/images/reservation.jpg\" border=\"0\" style=\"\"/></td></tr></table>");
			}

			//색지정
			if(reservation_cnt==0){//예약 없을때
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fefefe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style) );

			}else if(reservation_cnt==list.size()){//예약 모두 찬거
				textCal.append(tdHtml.toString()
						.replace("@bgcolor", "#fafc98")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style) );
			}else{//예약 조금 찬거
				textCal.append(tdHtml.toString()
						.replace("@bgcolor", "#fef0fe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style) );
			}

			textCal.append("				</td>");
			textCal.append("			</tr>");
			textCal.append("		</tbody>");
			textCal.append("	</table>");
			textCal.append("</td>");
			
			if(startDate % 7==0){
				textCal.append("</tr>");
				if(sMonthWeek==chkWeek){
					break;
				}
				textCal.append("<tr class=\"tt\" align=\"center\">");
				chkWeek++;
			}
			drawCal.add(Calendar.DATE, 1);
			
		}
			

		
		mav.addObject("txtCal",textCal.toString());
		
		
		mav.addObject("pensionInfo",pensionInfo);

		vo.setSb_type("brd");
		mav.addObject("brdList", service.pere100Q(vo));
		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));
		

		//이미지 사이즈 구하기
		String popImg = (String) pensionInfo.get("event_img");
		if(null != popImg && !"".equals(popImg)){
			String FilePath = req.getSession().getServletContext().getRealPath(popImg);
			File eventImg = new File(FilePath);
			if(eventImg.isFile()){
				  Image img = new ImageIcon(FilePath).getImage();
		            mav.addObject("eventW", img.getWidth(null));
		            mav.addObject("eventH", img.getHeight(null));
			}
		}
		
		return mav;
	}

	
	/**
	 * 객실정보 불러오기
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere101Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		jsonMap.put("list", service.pere101Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}
	
	/**
	 * 예약하기
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere200Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView();
		Calendar d1 = Calendar.getInstance();
		Calendar d2 = Calendar.getInstance();//오늘   
		int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0,4));
		int mm = Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
		int dd = Integer.parseInt(vo.getReservation_dt().substring(6,8));
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		d1.set(yyyy,mm,dd);//지정일.
		if(d1.getTime().getTime()-d2.getTime().getTime()<0){
			//오늘 이전은 조회할수 없습니다.
			
			mav.setViewName("redirect:./pere200Q.do?p_id="+vo.getP_id()+"&reservation_dt="+frmDate.format(d2.getTime())+"&sel_pr_no="+vo.getSel_pr_no());
			return mav;
		}

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
//		Map pensionInfo = service.pere203Q(vo);
		int reservation_use_month = (Integer) pensionInfo.get("reservation_use_month");
		
		//설정한 기간 지나면 튕기도록 설정
		if(0<reservation_use_month){
//			d2
//			yyyy = Integer.parseInt(vo.getReservation_dt().substring(0,4));
//			mm = Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
//			dd = Integer.parseInt(vo.getReservation_dt().substring(6,8));

			d2.add(Calendar.MONTH,reservation_use_month);
//			d2.set(Calendar.DATE,d2.getActualMaximum(Calendar.DATE));
			if(d1.getTime().getTime()-d2.getTime().getTime()>0){
//				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				mav.setViewName("redirect:./pere200Q.do?p_id="+vo.getP_id()+"&reservation_dt="+frmDate.format(d2.getTime()));
				
				
				mav.setViewName("/common/close");
//				ModelAndView mav = new ModelAndView("/common/close");
				mav.addObject("redirect","./pere200Q.do?p_id="+vo.getP_id()+"&reservation_dt="+frmDate.format(d2.getTime()));
				mav.addObject("msg",reservation_use_month+"개월내에만 예약가능");
				return mav;
			}
			
		}
		

		//부가서비스 가져오기
		mav.addObject("serviceList", service.pere200Q(vo));
		vo.setSb_type("brd");
		mav.addObject("brdList", service.pere100Q(vo));
		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));
		return mav;
	}
	
	/**
	 * 예약정보 가져와서 달력에 표시하기
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere200_1Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		Calendar d1 = Calendar.getInstance();//오늘

		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0,4));
		int mm = Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
		int dd = 1;
		
		
		d1.set(yyyy,mm,dd);//지정일.
		d1.add(Calendar.MONTH,1);
		vo.setReservation_dt(vo.getReservation_dt().substring(0,6)+"%");
		
		vo.setReservation_next_dt(frmDate.format(d1.getTime())+"%");
		
		jsonMap.put("list", service.pere200_1Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}
	
	/**
	 * 예약확인페이지 에서 객실별 예약현황 조회
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere200_2Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		Calendar d1 = Calendar.getInstance();//오늘       

		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0,4));
		int mm = Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
		int dd = 1;
		
		
		d1.set(yyyy,mm,dd);//지정일.
		d1.add(Calendar.MONTH,1);
		vo.setReservation_dt(vo.getReservation_dt().substring(0,6)+"%");
		
		vo.setReservation_next_dt(frmDate.format(d1.getTime())+"%");
		
		jsonMap.put("list", service.pere200_2Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}
	
	/**
	 * 예약확인페이지 에서 객실별 예약현황 조회
	 * 관리자용 정보 표시
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere200_3Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		Calendar d1 = Calendar.getInstance();//오늘       

		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0,4));
		int mm = Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
		int dd = 1;
		
		
		d1.set(yyyy,mm,dd);//지정일.
		d1.add(Calendar.MONTH,1);
		vo.setReservation_dt(vo.getReservation_dt().substring(0,6)+"%");
		
		vo.setReservation_next_dt(frmDate.format(d1.getTime())+"%");
		
		jsonMap.put("list", service.pere200_3Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}
	
	
	/**
	 * 기간, 프로모션, 예약사항 정보 조회
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere201Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();//오늘       

		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0,4));
		int mm = Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
		int dd = Integer.parseInt(vo.getReservation_dt().substring(6,8));
		
		
		d1.set(yyyy,mm,dd);//지정일.
		d1.add(Calendar.DATE,8);
		vo.setReservation_next_dt(frmDate.format(d1.getTime()));
		jsonMap.put("list", service.pere201Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}
	
	/**
	 * 환불규정 동의
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere202Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView();
		String reservation_dt = vo.getReservation_dt();
		String p_id = vo.getP_id();
		int yyyy = Integer.parseInt(reservation_dt.substring(0,4));
		int mm = Integer.parseInt(reservation_dt.substring(4,6))-1;
		int dd = Integer.parseInt(reservation_dt.substring(6,8));
		
		int totalPay = 0;
		
		int totalPayD1 = 0;
		int totalPayD2 = 0;
		int addPay = 0;
		
		List returnList = new ArrayList();
		
		vo.setP_id(p_id);
		
		//펜션 요금 조회
		for(int i=0;i< vo.getPr_no_cnts().length;i++){
			
			int pr_no = (int) vo.getPr_nos()[vo.getPr_no_cnts()[i]];
			int man_cnt = (int) vo.getMan_cnts()[vo.getPr_no_cnts()[i]];
			int chi_cnt = (int) vo.getChi_cnts()[vo.getPr_no_cnts()[i]];
			int rsv_days = (int) vo.getRsv_days()[vo.getPr_no_cnts()[i]];
			
			vo.setPr_no(pr_no);
			Map payInfo = service.pere202_1Q(vo);
			
			List nextDates = new ArrayList();
			
			//연속된 방의 가격 다시 구하기
			for(int j=0; j<rsv_days;j++){
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d1 = Calendar.getInstance();//오늘       
				
				d1.set(yyyy,mm,dd);//지정일.
				d1.add(Calendar.DATE,j);
//				    //요일 출력.

				SimpleDateFormat weekday222 = new SimpleDateFormat("yyyy-MM-dd");
				
				SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",java.util.Locale.KOREAN);
				SimpleDateFormat weekday = new SimpleDateFormat("EEE",java.util.Locale.KOREAN);
				
				nextDates.add(frmDate.format(d1.getTime()));
			}
			vo.setNext_dates(nextDates);
			List pList =  service.pere202_2Q(vo);
			
			
			
			for(int j=0; j<pList.size();j++){
				Map map = (Map) pList.get(j);
				String pm_dt = (String) map.get("pm_dt");
				//해당 날짜
				String aa = (String) map.get("aa");
				Map returnMap = new HashMap();
				returnMap.put("reservation_dt", aa);
				
				returnMap.put("rowspan", pList.size());
				returnMap.put("man_cnt", man_cnt);
				returnMap.put("chi_cnt", chi_cnt);
				returnMap.put("room_nm", payInfo.get("room_nm"));
				int add_usr_pay = (Integer) payInfo.get("add_usr_pay");
				returnMap.put("add_usr_pay", add_usr_pay);
				

				int totalMan = man_cnt+chi_cnt;
				returnMap.put("totalMan", totalMan);
				returnMap.put("use_man_cnt", payInfo.get("use_man_cnt"));
				//인원수에 따른 가격 설정
				int use_man_cnt = (Integer) payInfo.get("use_man_cnt");
				int pay_man = totalMan-use_man_cnt;
				if(pay_man<0){
					pay_man=0;
				}
				returnMap.put("pay_man", pay_man);
				int pay_man_m = pay_man*(add_usr_pay*1000);
				returnMap.put("pay_man_m", pay_man_m);
				addPay+=pay_man_m;
				totalPay+=pay_man_m;
				//인원수에 따른 가격 설정 끝
				
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d11 = Calendar.getInstance();//오늘       
				

				returnMap.put("nowdt", frmDate.format(d11.getTime()));
				
				if(null!=pm_dt && !"".equals(pm_dt)){
					//설정된 값이 있을때
					int pm_pay=Integer.parseInt( String.valueOf( map.get("o_pm_pay")));
					returnMap.put("pay", pm_pay);
					int pm_per = Integer.parseInt( String.valueOf( map.get("pm_per")));
					int pm_dc_m = Integer.parseInt( String.valueOf( map.get("pm_dc_m")));
					
					if(pm_per!=0 || pm_dc_m!=0 ){
						int dc_pay=Integer.parseInt( String.valueOf( map.get("o_pm_pay")))-Integer.parseInt( String.valueOf( map.get("pm_pay")));
						returnMap.put("dc_pay", dc_pay);
						totalPay-=dc_pay;
						totalPayD1-=dc_pay;
					}else{
						returnMap.put("dc_pay", 0);
					}
					
					totalPay+=pm_pay;
					totalPayD1+=pm_pay;
				}else{
					//설정된 값이 없을때 기본값

					int yyyy1 = Integer.parseInt(aa.substring(0,4));
					int mm1 = Integer.parseInt(aa.substring(4,6))-1;
					int dd1 = Integer.parseInt(aa.substring(6,8));
					System.out.println("aa : "+aa);
					Calendar d1 = Calendar.getInstance();//오늘       

					d1.set(yyyy1,mm1,dd1);//지정일.
//					    //요일 출력.
					SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",java.util.Locale.KOREAN);
					String dayOfTheWeek = weekday2.format(d1.getTime());
					System.out.println("dayOfTheWeek : "+dayOfTheWeek);
					int pm_pay=0;
					if("일".equals(dayOfTheWeek)
							||"월".equals(dayOfTheWeek)
							||"화".equals(dayOfTheWeek)
							||"수".equals(dayOfTheWeek)
							||"목".equals(dayOfTheWeek)
							){
						pm_pay = (Integer)payInfo.get("busy_1_base")*1000;
					}else if("금".equals(dayOfTheWeek)){
						pm_pay = (Integer)payInfo.get("busy_1_fri")*1000;
					}else if("토".equals(dayOfTheWeek)){
						pm_pay = (Integer)payInfo.get("busy_1_sat")*1000;
					}
					returnMap.put("dc_pay", 0);
					returnMap.put("pay", pm_pay);
					
					totalPay+=pm_pay;
					totalPayD1+=pm_pay;
				}
				
				
				returnList.add(returnMap);
			}
		}
		
		//객식 총 가격
//		totalPayD1 = totalPay;
		
		List rtAddSvcList= new ArrayList();
		//부가서비스 가격 조회
		if(vo.getAs_no_idxs()!=null && vo.getAs_no_idxs().length>0){
			List addServiceList = service.pere200Q(vo);
			for(int i=0;i< vo.getAs_no_idxs().length;i++){
				int as_no = (int) vo.getAs_nos()[vo.getAs_no_idxs()[i]];
				int use_cnt = (int) vo.getUse_cnts()[vo.getAs_no_idxs()[i]];
				String req_msg = vo.getReq_msgs()[vo.getAs_no_idxs()[i]];
				
				for(int jj=0; jj<addServiceList.size();jj++){
					Map map = (Map) addServiceList.get(jj);
					int mAs_no = (Integer) map.get("as_no");
					if(mAs_no==as_no){
						int as_pay =  (Integer) map.get("as_pay");
						map.put("use_cnt", use_cnt);
						map.put("totalPay", (use_cnt*as_pay));
						map.put("req_msg", req_msg);
						rtAddSvcList.add(map);
						totalPayD2 +=use_cnt*as_pay;
						break;
					}
				}
				
			}
			
		}
		totalPay+=totalPayD2;
		
		mav.addObject("list",returnList);
		
		mav.addObject("totalPay",totalPay);
		mav.addObject("totalPayD1",totalPayD1);
		mav.addObject("totalPayD2",totalPayD2);
		mav.addObject("addPay",addPay);
		
		mav.addObject("paramMap",vo);
//		mav.addObject("p_id",p_id);
		
//		mav.addObject("list",returnList);
//		환불규정
		mav.addObject("refundList",service.pere202_3Q(vo));
		
		//부가서비스 리턴
		mav.addObject("rtAddSvcList",rtAddSvcList);

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
		return mav;
	}
	
	/**
	 * 예약하기
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere203Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView();
		String reservation_dt = vo.getReservation_dt();
		String p_id = vo.getP_id();
		int yyyy = Integer.parseInt(reservation_dt.substring(0,4));
		int mm = Integer.parseInt(reservation_dt.substring(4,6))-1;
		int dd = Integer.parseInt(reservation_dt.substring(6,8));
		
		//기본 예약상태로 저장함
		vo.setRm_status("R");
		
		int totalPay = 0;
		
		int totalPayD1 = 0;
		int totalPayD2 = 0;
		int addPay = 0;
		
		List returnList = new ArrayList();
		
		vo.setP_id(p_id);
		
		//펜션 요금 조회
		for(int i=0;i< vo.getPr_no_cnts().length;i++){
			
			int pr_no = (int) vo.getPr_nos()[vo.getPr_no_cnts()[i]];
			int man_cnt = (int) vo.getMan_cnts()[vo.getPr_no_cnts()[i]];
			int chi_cnt = (int) vo.getChi_cnts()[vo.getPr_no_cnts()[i]];
			int rsv_days = (int) vo.getRsv_days()[vo.getPr_no_cnts()[i]];
			
			vo.setPr_no(pr_no);
			Map payInfo = service.pere202_1Q(vo);
			
			List nextDates = new ArrayList();
			
			//연속된 방의 가격 다시 구하기
			for(int j=0; j<rsv_days;j++){
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d1 = Calendar.getInstance();//오늘       
				
				d1.set(yyyy,mm,dd);//지정일.
				d1.add(Calendar.DATE,j);
//				    //요일 출력.

				SimpleDateFormat weekday222 = new SimpleDateFormat("yyyy-MM-dd");
				
				SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",java.util.Locale.KOREAN);
				SimpleDateFormat weekday = new SimpleDateFormat("EEE",java.util.Locale.KOREAN);
				nextDates.add(frmDate.format(d1.getTime()));
			}
			vo.setNext_dates(nextDates);
			List pList =  service.pere202_2Q(vo);
			
			
			
			for(int j=0; j<pList.size();j++){
				Map map = (Map) pList.get(j);
				String pm_dt = (String) map.get("pm_dt");
				//해당 날짜
				String aa = (String) map.get("aa");
				Map returnMap = new HashMap();
				returnMap.put("reservation_dt", aa);
				
				returnMap.put("rowspan", pList.size());
				returnMap.put("man_cnt", man_cnt);
				returnMap.put("chi_cnt", chi_cnt);
				returnMap.put("room_nm", payInfo.get("room_nm"));
				int add_usr_pay = (Integer) payInfo.get("add_usr_pay");
				returnMap.put("add_usr_pay", add_usr_pay);
				

				int totalMan = man_cnt+chi_cnt;
				returnMap.put("totalMan", totalMan);
				returnMap.put("use_man_cnt", payInfo.get("use_man_cnt"));
				//인원수에 따른 가격 설정
				int use_man_cnt = (Integer) payInfo.get("use_man_cnt");
				int pay_man = totalMan-use_man_cnt;
				if(pay_man<0){
					pay_man=0;
				}
				returnMap.put("pay_man", pay_man);
				int pay_man_m = pay_man*(add_usr_pay*1000);
				returnMap.put("pay_man_m", pay_man_m);
				addPay+=pay_man_m;
				totalPay+=pay_man_m;
				//인원수에 따른 가격 설정 끝
				
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d11 = Calendar.getInstance();//오늘       
				

				returnMap.put("nowdt", frmDate.format(d11.getTime()));
				
				if(null!=pm_dt && !"".equals(pm_dt)){
					//설정된 값이 있을때
					int pm_pay=Integer.parseInt( String.valueOf( map.get("o_pm_pay")));
					returnMap.put("pay", pm_pay);
					int pm_per = Integer.parseInt( String.valueOf( map.get("pm_per")));
					int pm_dc_m = Integer.parseInt( String.valueOf( map.get("pm_dc_m")));
					
					if(pm_per!=0 || pm_dc_m!=0 ){
						int dc_pay=Integer.parseInt( String.valueOf( map.get("o_pm_pay")))-Integer.parseInt( String.valueOf( map.get("pm_pay")));
						returnMap.put("dc_pay", dc_pay);
						totalPay-=dc_pay;
						totalPayD1-=dc_pay;
					}else{
						returnMap.put("dc_pay", 0);
					}
					
					totalPay+=pm_pay;
					totalPayD1+=pm_pay;
				}else{
					//설정된 값이 없을때 기본값

					int yyyy1 = Integer.parseInt(aa.substring(0,4));
					int mm1 = Integer.parseInt(aa.substring(4,6))-1;
					int dd1 = Integer.parseInt(aa.substring(6,8));
					
					Calendar d1 = Calendar.getInstance();//오늘       

					d1.set(yyyy1,mm1,dd1);//지정일.
//					    //요일 출력.
					SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",java.util.Locale.KOREAN);
					String dayOfTheWeek = weekday2.format(d1.getTime());

					int pm_pay=0;
					if("일".equals(dayOfTheWeek)
							||"월".equals(dayOfTheWeek)
							||"화".equals(dayOfTheWeek)
							||"수".equals(dayOfTheWeek)
							||"목".equals(dayOfTheWeek)
							){
						pm_pay = (Integer)payInfo.get("busy_1_base")*1000;
					}else if("금".equals(dayOfTheWeek)){
						pm_pay = (Integer)payInfo.get("busy_1_fri")*1000;
					}else if("토".equals(dayOfTheWeek)){
						pm_pay = (Integer)payInfo.get("busy_1_sat")*1000;
					}
					returnMap.put("dc_pay", 0);
					returnMap.put("pay", pm_pay);
					
					totalPay+=pm_pay;
					totalPayD1+=pm_pay;
				}
				
				
				returnList.add(returnMap);
			}
		}
		
		//객식 총 가격
//		totalPayD1 = totalPay;
		
		List rtAddSvcList= new ArrayList();
		//부가서비스 가격 조회
		if(vo.getAs_no_idxs()!=null && vo.getAs_no_idxs().length>0){
			List addServiceList = service.pere200Q(vo);
			for(int i=0;i< vo.getAs_no_idxs().length;i++){
				int as_no = (int) vo.getAs_nos()[vo.getAs_no_idxs()[i]];
				int use_cnt = (int) vo.getUse_cnts()[vo.getAs_no_idxs()[i]];
				String req_msg = vo.getReq_msgs()[vo.getAs_no_idxs()[i]];
				
				for(int jj=0; jj<addServiceList.size();jj++){
					Map map = (Map) addServiceList.get(jj);
					int mAs_no = (Integer) map.get("as_no");
					if(mAs_no==as_no){
						int as_pay =  (Integer) map.get("as_pay");
						map.put("use_cnt", use_cnt);
						map.put("totalPay", (use_cnt*as_pay));
						map.put("req_msg", req_msg);
						rtAddSvcList.add(map);
						totalPayD2 +=use_cnt*as_pay;
						break;
					}
				}
				
			}
			
		}
		totalPay+=totalPayD2;
		
		mav.addObject("list",returnList);
		
		mav.addObject("totalPay",totalPay);
		mav.addObject("totalPayD1",totalPayD1);
		mav.addObject("totalPayD2",totalPayD2);
		mav.addObject("addPay",addPay);
		
		mav.addObject("paramMap",vo);

//		환불규정
//		mav.addObject("refundList",service.pere202_3Q(vo));
		
		//부가서비스 리턴
		mav.addObject("rtAddSvcList",rtAddSvcList);
		
		COMAVo codeVo = new COMAVo();
		//전화번호
		codeVo.setCode_p_no("02");
		mav.addObject("code1List",comaService.coma104Q(codeVo));
		//이메일
		codeVo.setCode_p_no("03");
		mav.addObject("code2List",comaService.coma104Q(codeVo));
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
		
		List aList = petiService.peti300_1Q(petiVo);
		
		List aList1=new ArrayList();
		List aList2=new ArrayList();
		List aList3=new ArrayList();
		List aList4=new ArrayList();
		
		if(aList!=null && 0<aList.size()){
			for( int i=0; i< aList.size();i++){
				Map map = (Map) aList.get(i);
				if("1".equals(map.get("paa_type"))){
					//계좌
					aList1.add(map);
				}else if("2".equals(map.get("paa_type"))){
					//픽업장소
					aList2.add(map);
				}else if("3".equals(map.get("paa_type"))){
					//픽업정보
					aList3.add(map);
				}else if("4".equals(map.get("paa_type"))){
					//도착시간
					aList4.add(map);
				}
			}
		}
		mav.addObject("aList1", aList1);
		mav.addObject("aList2", aList2);
		mav.addObject("aList3", aList3);
		mav.addObject("aList4", aList4);
		
		return mav;
	}
	
	/**
	 * phone 체크
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere203_1Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView();
		//세션 초기화
		req.getSession().setAttribute("smsChk", "");
		COMAVo codeVo = new COMAVo();
		//전화번호
		codeVo.setCode_p_no("02");
		mav.addObject("code1List",comaService.coma104Q(codeVo));
		return mav;
	}

	/**
	 * sms 인증
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere203_2Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		if("Y".equals(pensionInfo.get("phone_yn"))){
			//sms 인증해야하는 부분
			
			Random rnd =new Random();
			StringBuffer buf =new StringBuffer();
			 
			for(int i=0;i<6;i++){
				buf.append((rnd.nextInt(10))); 
			}
				
			SMSUtil smsUtil = new SMSUtil();
			
			String send = pensionInfo.get("p_tel1")+"-"+pensionInfo.get("p_tel2")+"-"+pensionInfo.get("p_tel3");
			String recive = vo.getR_phone1()+"-"+vo.getR_phone2()+"-"+vo.getR_phone3();
			String msg = "["+pensionInfo.get("p_nm")+"]인증번호 "+buf.toString();
			
			String returnCode = smsUtil.send(send, recive, JspUtil.getByteSizeToString(msg.toString(),80));
			
			if("1".equals(returnCode)){
				//보내기 성공
				req.getSession().setAttribute("smsChk", buf.toString());
				jsonMap.put("returnType", "1");
								
			}else{
				//보내기 실패
				jsonMap.put("returnType", "3");
			}
			//sms 히스토리에 넣기
			vo.setP_nm((String) pensionInfo.get("p_nm") );
			vo.setFrom_no(send);
			vo.setTo_no(recive);
			vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),80));
			vo.setC_code(returnCode);
			vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
			
			service.pere710Q(vo);
			if("1".equals(returnCode)){
				//sms 카운트 줄이기
				service.pere711Q(vo);
			}
		}else{
			//바로 저장 완료
			jsonMap.put("returnType", "2");
		}
		mav.addObject("map", jsonMap);
//		r_phone2
		
		return mav;
	}
	
	/**
	 * 인증값과 같은지 비교
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere203_3Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {

		ModelAndView mav = new ModelAndView("common/toJson");
		
		String smsChk= (String) req.getSession().getAttribute("smsChk");
		
		Map jsonMap = new HashMap();
		if(vo.getSms_chk_data().equals(smsChk)){
			//인증번호 일치할때
			jsonMap.put("checkYN", "Y");
		}else{
			//인증번호 불일치
			jsonMap.put("checkYN", "N");
		}
		mav.addObject("map", jsonMap);
		return mav;
	}
	
	/**
	 * 예약 확인
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere204Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView();
		
		String reservation_dt = vo.getReservation_dt();
		String p_id = vo.getP_id();
		int yyyy = Integer.parseInt(reservation_dt.substring(0,4));
		int mm = Integer.parseInt(reservation_dt.substring(4,6))-1;
		int dd = Integer.parseInt(reservation_dt.substring(6,8));
		
		int totalPay = 0;
		
		int totalPayD1 = 0;
		int totalPayD2 = 0;
		int addPay = 0;
		
		List returnList = new ArrayList();
		
		vo.setP_id(p_id);
		
		//펜션 요금 조회
		for(int i=0;i< vo.getPr_no_cnts().length;i++){
			
			int pr_no = (int) vo.getPr_nos()[vo.getPr_no_cnts()[i]];
			int man_cnt = (int) vo.getMan_cnts()[vo.getPr_no_cnts()[i]];
			int chi_cnt = (int) vo.getChi_cnts()[vo.getPr_no_cnts()[i]];
			int rsv_days = (int) vo.getRsv_days()[vo.getPr_no_cnts()[i]];
			
			vo.setPr_no(pr_no);
			Map payInfo = service.pere202_1Q(vo);
			
			List nextDates = new ArrayList();
			
			//연속된 방의 가격 다시 구하기
			for(int j=0; j<rsv_days;j++){
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d1 = Calendar.getInstance();//오늘       
				
				d1.set(yyyy,mm,dd);//지정일.
				d1.add(Calendar.DATE,j);
//				    //요일 출력.

				SimpleDateFormat weekday222 = new SimpleDateFormat("yyyy-MM-dd");
				
				SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",java.util.Locale.KOREAN);
				SimpleDateFormat weekday = new SimpleDateFormat("EEE",java.util.Locale.KOREAN);
				
				nextDates.add(frmDate.format(d1.getTime()));
			}
			vo.setNext_dates(nextDates);
			List pList =  service.pere202_2Q(vo);
			
			
			
			for(int j=0; j<pList.size();j++){
				Map map = (Map) pList.get(j);
				String pm_dt = (String) map.get("pm_dt");
				//해당 날짜
				String aa = (String) map.get("aa");
				Map returnMap = new HashMap();
				returnMap.put("reservation_dt", aa);
				
				returnMap.put("rowspan", pList.size());
				returnMap.put("man_cnt", man_cnt);
				returnMap.put("chi_cnt", chi_cnt);
				returnMap.put("room_nm", payInfo.get("room_nm"));
				int add_usr_pay = (Integer) payInfo.get("add_usr_pay");
				returnMap.put("add_usr_pay", add_usr_pay);
				

				int totalMan = man_cnt+chi_cnt;
				returnMap.put("totalMan", totalMan);
				returnMap.put("use_man_cnt", payInfo.get("use_man_cnt"));
				//인원수에 따른 가격 설정
				int use_man_cnt = (Integer) payInfo.get("use_man_cnt");
				int pay_man = totalMan-use_man_cnt;
				if(pay_man<0){
					pay_man=0;
				}
				returnMap.put("pay_man", pay_man);
				int pay_man_m = pay_man*(add_usr_pay*1000);
				returnMap.put("pay_man_m", pay_man_m);
				addPay+=pay_man_m;
				totalPay+=pay_man_m;
				//인원수에 따른 가격 설정 끝
				
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d11 = Calendar.getInstance();//오늘       
				

				returnMap.put("nowdt", frmDate.format(d11.getTime()));
				
				if(null!=pm_dt && !"".equals(pm_dt)){
					//설정된 값이 있을때
					int pm_pay=Integer.parseInt( String.valueOf( map.get("o_pm_pay")));
					returnMap.put("pay", pm_pay);
					int pm_per = Integer.parseInt( String.valueOf( map.get("pm_per")));
					int pm_dc_m = Integer.parseInt( String.valueOf( map.get("pm_dc_m")));
					
					if(pm_per!=0 || pm_dc_m!=0 ){
						int dc_pay=Integer.parseInt( String.valueOf( map.get("o_pm_pay")))-Integer.parseInt( String.valueOf( map.get("pm_pay")));
						returnMap.put("dc_pay", dc_pay);
						totalPay-=dc_pay;
						totalPayD1-=dc_pay;
					}else{
						returnMap.put("dc_pay", 0);
					}
					
					totalPay+=pm_pay;
					totalPayD1+=pm_pay;
				}else{
					//설정된 값이 없을때 기본값

					int yyyy1 = Integer.parseInt(aa.substring(0,4));
					int mm1 = Integer.parseInt(aa.substring(4,6))-1;
					int dd1 = Integer.parseInt(aa.substring(6,8));
					
					Calendar d1 = Calendar.getInstance();//오늘       

					d1.set(yyyy1,mm1,dd1);//지정일.
//					    //요일 출력.
					SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",java.util.Locale.KOREAN);
					String dayOfTheWeek = weekday2.format(d1.getTime());

					int pm_pay=0;
					if("일".equals(dayOfTheWeek)
							||"월".equals(dayOfTheWeek)
							||"화".equals(dayOfTheWeek)
							||"수".equals(dayOfTheWeek)
							||"목".equals(dayOfTheWeek)
							){
						pm_pay = (Integer)payInfo.get("busy_1_base")*1000;
					}else if("금".equals(dayOfTheWeek)){
						pm_pay = (Integer)payInfo.get("busy_1_fri")*1000;
					}else if("토".equals(dayOfTheWeek)){
						pm_pay = (Integer)payInfo.get("busy_1_sat")*1000;
					}
					returnMap.put("dc_pay", 0);
					returnMap.put("pay", pm_pay);
					
					totalPay+=pm_pay;
					totalPayD1+=pm_pay;
				}
				
				
				returnList.add(returnMap);
			}
		}
		
		//객식 총 가격
//		totalPayD1 = totalPay;
		
		List rtAddSvcList= new ArrayList();
		//부가서비스 가격 조회
		if(vo.getAs_no_idxs()!=null && vo.getAs_no_idxs().length>0){
			List addServiceList = service.pere200Q(vo);
			for(int i=0;i< vo.getAs_no_idxs().length;i++){
				int as_no = (int) vo.getAs_nos()[vo.getAs_no_idxs()[i]];
				int use_cnt = (int) vo.getUse_cnts()[vo.getAs_no_idxs()[i]];
				String req_msg = vo.getReq_msgs()[vo.getAs_no_idxs()[i]];
				
				for(int jj=0; jj<addServiceList.size();jj++){
					Map map = (Map) addServiceList.get(jj);
					int mAs_no = (Integer) map.get("as_no");
					if(mAs_no==as_no){
						int as_pay =  (Integer) map.get("as_pay");
						map.put("use_cnt", use_cnt);
						map.put("totalPay", (use_cnt*as_pay));
						map.put("req_msg", req_msg);
						rtAddSvcList.add(map);
						totalPayD2 +=use_cnt*as_pay;
						break;
					}
				}
				
			}
			
		}
		totalPay+=totalPayD2;
		
		mav.addObject("list",returnList);
		
		mav.addObject("totalPay",totalPay);
		mav.addObject("totalPayD1",totalPayD1);
		mav.addObject("totalPayD2",totalPayD2);
		mav.addObject("addPay",addPay);
		

		//부가서비스 리턴
		mav.addObject("rtAddSvcList",rtAddSvcList);

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
		Calendar chkDt = Calendar.getInstance();//오늘       
		
		int tm = (Integer) pensionInfo.get("wait_time");
		chkDt.add(Calendar.HOUR,tm);
		
		SimpleDateFormat frmChkDt = new SimpleDateFormat("yyyyMMddHHmmss");
		
		vo.setRm_wait_time(frmChkDt.format(chkDt.getTime()));

		mav.addObject("paramMap",vo);
		return mav;
	}
	
	
	/**
	 * 예약 저장하기(사용자)
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere204T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView("/common/close");
		String smsChk= (String) req.getSession().getAttribute("smsChk");
		if(vo.getSms_chk_data()!=null && !vo.getSms_chk_data().equals(smsChk)){
			mav.addObject("historyBackYn","Y");
			mav.addObject("msg","SMS 인증번호가 없습니다");
			return mav;
		}
		//기본 예약상태로 저장함
		vo.setRm_status("R");

		//sms 방명, 숙박일, 등록일
		String smsRoom_nm = "";
		String smsReservation_dt = "";
		String smsReg_dt = "";
		
		String reservation_dt = vo.getReservation_dt();
		String p_id = vo.getP_id();
		int yyyy = Integer.parseInt(reservation_dt.substring(0,4));
		int mm = Integer.parseInt(reservation_dt.substring(4,6))-1;
		int dd = Integer.parseInt(reservation_dt.substring(6,8));
		
		int totalPay = 0;
		
		int totalPayD1 = 0;
		int totalPayD2 = 0;
		int addPay = 0;
		
		List returnList = new ArrayList();
		
		vo.setP_id(p_id);
		
		//시작일시 저장 sms
		String startDate="";
		String startRooms="";
		//sms 보낼때 몇박인지
		int bak=0;
		//펜션 요금 조회
		for(int i=0;i< vo.getPr_no_cnts().length;i++){
			
			int pr_no = (int) vo.getPr_nos()[vo.getPr_no_cnts()[i]];
			int man_cnt = (int) vo.getMan_cnts()[vo.getPr_no_cnts()[i]];
			int chi_cnt = (int) vo.getChi_cnts()[vo.getPr_no_cnts()[i]];
			int rsv_days = (int) vo.getRsv_days()[vo.getPr_no_cnts()[i]];
			
			vo.setPr_no(pr_no);
			Map payInfo = service.pere202_1Q(vo);
			
			List nextDates = new ArrayList();
			
			//연속된 방의 가격 다시 구하기
			for(int j=0; j<rsv_days;j++){
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d1 = Calendar.getInstance();//오늘       
				
				d1.set(yyyy,mm,dd);//지정일.
				d1.add(Calendar.DATE,j);
//				    //요일 출력.
				nextDates.add(frmDate.format(d1.getTime()));
			}
			vo.setNext_dates(nextDates);
			List pList =  service.pere202_2Q(vo);
			
			for(int j=0; j<pList.size();j++){
				bak++;
				Map map = (Map) pList.get(j);
				String pm_dt = (String) map.get("pm_dt");
				//해당 날짜
				String aa = (String) map.get("aa");
				Map returnMap = new HashMap();
				returnMap.put("reservation_dt", aa);
				if(i==0){
					int yyyy1 = Integer.parseInt(aa.substring(0,4));
					int mm1 = Integer.parseInt(aa.substring(4,6))-1;
					int dd1 = Integer.parseInt(aa.substring(6,8));

					startDate=aa.substring(0,4)+"-"+aa.substring(4,6)+"-"+aa.substring(6,8);
					startRooms=(String) payInfo.get("room_nm");
				}
				
				returnMap.put("pr_no", pr_no);
				returnMap.put("rowspan", pList.size());
				returnMap.put("man_cnt", man_cnt);
				returnMap.put("chi_cnt", chi_cnt);
				returnMap.put("room_nm", payInfo.get("room_nm"));
				int add_usr_pay = (Integer) payInfo.get("add_usr_pay");
				returnMap.put("add_usr_pay", add_usr_pay);
				

				int totalMan = man_cnt+chi_cnt;
				returnMap.put("totalMan", totalMan);
				returnMap.put("use_man_cnt", payInfo.get("use_man_cnt"));
				//인원수에 따른 가격 설정
				int use_man_cnt = (Integer) payInfo.get("use_man_cnt");
				int pay_man = totalMan-use_man_cnt;
				if(pay_man<0){
					pay_man=0;
				}
				returnMap.put("pay_man", pay_man);
				int pay_man_m = pay_man*(add_usr_pay*1000);
				returnMap.put("pay_man_m", pay_man_m);
				addPay+=pay_man_m;
				totalPay+=pay_man_m;
				//인원수에 따른 가격 설정 끝
				
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d11 = Calendar.getInstance();//오늘       
				
				//sms 관련 정보
				if(i==0 && j==0){
					SimpleDateFormat weekday222 = new SimpleDateFormat("yyyy-MM-dd");
					smsRoom_nm = startRooms;
					smsReservation_dt = startDate;
					smsReg_dt = weekday222.format(d11.getTime());
//					if(vo.getPr_no_cnts().length>1){
//						smsRoom_nm = startRooms+".";
//						smsReservation_dt = startDate+".";
//					}else if(rsv_days>1){
//						smsReservation_dt = startDate+".";
//					}
				}
				returnMap.put("nowdt", frmDate.format(d11.getTime()));
				
				if(null!=pm_dt && !"".equals(pm_dt)){
					//설정된 값이 있을때
					int pm_pay=Integer.parseInt( String.valueOf( map.get("o_pm_pay")));
					returnMap.put("pay", pm_pay);
					int pm_per = Integer.parseInt( String.valueOf( map.get("pm_per")));
					int pm_dc_m = Integer.parseInt( String.valueOf( map.get("pm_dc_m")));
					
					if(pm_per!=0 || pm_dc_m!=0 ){
						int dc_pay=Integer.parseInt( String.valueOf( map.get("o_pm_pay")))-Integer.parseInt( String.valueOf( map.get("pm_pay")));
						returnMap.put("dc_pay", dc_pay);
						totalPay-=dc_pay;
						totalPayD1-=dc_pay;
					}else{
						returnMap.put("dc_pay", 0);
					}
					
					totalPay+=pm_pay;
					totalPayD1+=pm_pay;
				}else{
					//설정된 값이 없을때 기본값

					int yyyy1 = Integer.parseInt(aa.substring(0,4));
					int mm1 = Integer.parseInt(aa.substring(4,6))-1;
					int dd1 = Integer.parseInt(aa.substring(6,8));
					
					Calendar d1 = Calendar.getInstance();//오늘       

					d1.set(yyyy1,mm1,dd1);//지정일.
//					    //요일 출력.
					SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",java.util.Locale.KOREAN);
					String dayOfTheWeek = weekday2.format(d1.getTime());

					int pm_pay=0;
					if("일".equals(dayOfTheWeek)
							||"월".equals(dayOfTheWeek)
							||"화".equals(dayOfTheWeek)
							||"수".equals(dayOfTheWeek)
							||"목".equals(dayOfTheWeek)
							){
						pm_pay = (Integer)payInfo.get("busy_1_base")*1000;
					}else if("금".equals(dayOfTheWeek)){
						pm_pay = (Integer)payInfo.get("busy_1_fri")*1000;
					}else if("토".equals(dayOfTheWeek)){
						pm_pay = (Integer)payInfo.get("busy_1_sat")*1000;
					}
					returnMap.put("dc_pay", 0);
					returnMap.put("pay", pm_pay);
					
					totalPay+=pm_pay;
					totalPayD1+=pm_pay;
				}
				
				
				returnList.add(returnMap);
			}
		}
		
		//객식 총 가격
//		totalPayD1 = totalPay;
		
		List rtAddSvcList= new ArrayList();
		//부가서비스 가격 조회
		if(vo.getAs_no_idxs()!=null && vo.getAs_no_idxs().length>0){
			List addServiceList = service.pere200Q(vo);
			for(int i=0;i< vo.getAs_no_idxs().length;i++){
				int as_no = (int) vo.getAs_nos()[vo.getAs_no_idxs()[i]];
				int use_cnt = (int) vo.getUse_cnts()[vo.getAs_no_idxs()[i]];
				String req_msg = vo.getReq_msgs()[vo.getAs_no_idxs()[i]];
				
				for(int jj=0; jj<addServiceList.size();jj++){
					Map map = (Map) addServiceList.get(jj);
					int mAs_no = (Integer) map.get("as_no");
					if(mAs_no==as_no){
						int as_pay =  (Integer) map.get("as_pay");
						
						map.put("as_no", mAs_no);
						map.put("use_cnt", use_cnt);
						map.put("totalPay", (use_cnt*as_pay));
						map.put("req_msg", req_msg);
						rtAddSvcList.add(map);
						totalPayD2 +=use_cnt*as_pay;
						break;
					}
				}
				
			}
			
		}
		totalPay+=totalPayD2;
		
		Map data = new HashMap();
		data.put("paramMap",vo);
		data.put("list",returnList);
		//부가서비스 리턴
		data.put("rtAddSvcList",rtAddSvcList);
//		
//		mav.addObject("totalPay",totalPay);
//		mav.addObject("totalPayD1",totalPayD1);
//		mav.addObject("totalPayD2",totalPayD2);
//		mav.addObject("addPay",addPay);
		
		//예약한 객실수 
		data.put("smsRoomCnt",vo.getPr_no_cnts().length);
		//총 가격
		data.put("totalPay",totalPay);
//		객실명
		data.put("smsRoom_nm",smsRoom_nm);
//		예약일
		data.put("smsReservation_dt",smsReservation_dt);
//		등록일
		data.put("smsReg_dt",smsReg_dt);
//		숙박일
		data.put("smsBak",bak);
		
		service.pere204T(data);
		
		mav.setViewName("/common/close");
		mav.addObject("redirect","./pere200Q.do?p_id="+vo.getP_id()+"&reservation_dt="+reservation_dt);
		mav.addObject("msg","예약되었습니다");
		return mav;
	}
	
	/**
	 * 예약안내
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere300Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView();
		Map jsonMap = new HashMap();
		mav.addObject("refundList",service.pere202_3Q(vo));
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
//		mav.addObject("pensionInfo",service.pere203Q(vo));
		return mav;
	}
	
	/**
	 * 요금설정
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere400Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();
		Map jsonMap = new HashMap();
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
		
		vo.setSb_type("brd");
		mav.addObject("brdList", service.pere100Q(vo));
		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));
		return mav;
	}
	
	/**
	 * 요금 저장 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere400T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./pere400Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","저장되었습니다");
		
		service.pere400T(vo);
		return mav;
	}
	
	/**
	 * 프로모션 정보 가져오기
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere400_1Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		Calendar d1 = Calendar.getInstance();//오늘       

		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0,4));
		int mm = Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
		int dd = 1;
		
		
		d1.set(yyyy,mm,dd);//지정일.
		d1.add(Calendar.MONTH,1);
		vo.setReservation_dt(vo.getReservation_dt().substring(0,6)+"%");
		vo.setReservation_next_dt(frmDate.format(d1.getTime())+"%");
		
		jsonMap.put("list", service.pere400_1Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}
	
	/**
	 * 펜션 예약 조회
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere500Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView();
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);

		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));
		
		COMAVo codeVo = new COMAVo();
		//전화번호
		codeVo.setCode_p_no("02");
		mav.addObject("code1List",comaService.coma104Q(codeVo));
		return mav;
	}
	
	/**
	 * 예약내용 불러오기 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere501Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView();
		
		List reservationList = service.pere501Q(vo);
		
		mav.addObject("reservationList", reservationList);

		if(null!=reservationList && 0<reservationList.size()){
			//자료가 있을때
			Map data = (Map) reservationList.get(0);
			mav.addObject("paramMap", data);
			
			if(vo.getRm_no() == 0){
				vo.setRm_no((Integer) data.get("rm_no"));
			}
			List list = service.pere501_2Q(vo);
			List returnList = new ArrayList();
			
			Calendar nowDate = Calendar.getInstance();//오늘
			nowDate.set(Calendar.HOUR_OF_DAY, 1);
			nowDate.set(Calendar.MINUTE, 1);
			nowDate.set(Calendar.SECOND, 1);
			

			boolean cancelBtn = true;
			for(int i = 0; i < list.size();i++){
				Map map =(Map) list.get(i);
				Calendar reservationDt = Calendar.getInstance();//오늘
				String reservation_dt =(String) map.get("reservation_dt"); 
				int yyyy = Integer.parseInt(reservation_dt.substring(0,4)) ;
				int mm = Integer.parseInt(reservation_dt.substring(4,6)) ;
				int dd = Integer.parseInt(reservation_dt.substring(6,8)) ;
				reservationDt.set(yyyy,mm-1,dd,1,1,1);
							
				if((nowDate.getTime().getTime()-reservationDt.getTime().getTime())>0){
					map.put("cancelYN", "N");
				}else{
					cancelBtn=false;
					map.put("cancelYN", "Y");
				}
				returnList.add(map);
			}
//			예약 객실목록
			mav.addObject("list", returnList);
			
			//예약 객실목록
//			mav.addObject("list", service.pere501_2Q(vo));
			
			//취소 객실 목록
			mav.addObject("cancelList", service.pere501_4Q(vo));
			
			//부가서비스 목록
			mav.addObject("rtAddSvcList", service.pere501_3Q(vo));
			mav.addObject("cancelBtn",cancelBtn);
		}else{
			//자료가 없을때
			mav.setViewName("/common/close");
			mav.addObject("redirect","./pere500Q.do?p_id="+vo.getP_id());
			mav.addObject("msg","등록된 예약 자료가 없습니다.");
			return mav;
		}
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
		
		return mav;
	}
	
	
	/**
	 * 펜션 예약취소(사용자)
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere502Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView();

		List pList = new ArrayList();
		List sList = new ArrayList();
		
		boolean chkComplet = false;
		if(vo.getIdxs()!=null && 0 < vo.getIdxs().length){
			for(int i=0; i<vo.getIdxs().length;i++){
				vo.setPr_no(vo.getPr_nos()[vo.getIdxs()[i]]);
				vo.setReservation_dt(vo.getReservation_dts()[vo.getIdxs()[i]]);
				Map pMap = service.pere502_1Q(vo);
				pList.add(pMap);
				if("C".equals(pMap.get("rm_status"))){
					//등록된 자료
					chkComplet=true;
				}
				
			}
		}
		if(vo.getIdxs2()!=null && 0 < vo.getIdxs2().length){
			for(int i=0; i<vo.getIdxs2().length;i++){
				vo.setAs_no(vo.getAs_nos()[vo.getIdxs2()[i]]);
				
				Map sMap =service.pere502_3Q(vo);	
				sList.add(sMap);
				if("C".equals(sMap.get("as_status"))){
					//등록된 자료
					chkComplet=true;
				}
			}
		}
		if(chkComplet){
			//환불 자료로 넘어간다
			mav = new ModelAndView("usr/pe/re/pere502Q");
//			mav.setViewName("/usr/pr/re/pere502Q");
			Map refund = service.pere202_3Q(vo);
			mav.addObject("refundList",refund);
			mav.addObject("paramMap",vo);
			//취소할 예약 객실목록
			
			if(pList!=null && 0<pList.size()){
				vo.setNext_dates(pList);
				List list = service.pere501_5Q(vo);
				List returnList = new ArrayList();
				if(list !=null && 0<list.size()){
					for(int i=0; i< list.size();i++){
						Map data = (Map) list.get(i);
						
						int dateCha = Integer.parseInt(String.valueOf( data.get("dateCha")));
						if(dateCha<0){
							dateCha=0;
						}
						if(dateCha>7){
							int per= (Integer) refund.get("general");
							data.put("per",  per);
							data.put("r_pay", (Integer) data.get("total_pay")-(Integer) data.get("add_pay"));
							int r_pay =Integer.parseInt( Long.toString( (long) (((Integer) data.get("total_pay")-(Integer) data.get("add_pay"))*(per/100.0))));
							
							r_pay = r_pay/1000;
							r_pay = r_pay*1000;
							data.put("r_pay", r_pay);
						}else{
							int per= (Integer) refund.get("day_a_"+dateCha);
							data.put("per", per);
							int r_pay =Integer.parseInt( Long.toString( (long) (((Integer) data.get("total_pay")-(Integer) data.get("add_pay"))*(per/100.0))));
							//절삭 처리
							r_pay = r_pay/1000;
							r_pay = r_pay*1000;
							data.put("r_pay", r_pay);
						}
						
						returnList.add(data);
					}
				}
//				refund
				
				mav.addObject("list", returnList);
			}
			
			
			//부가서비스 목록
			if(sList!=null && 0<sList.size()){
				vo.setNext_dates(sList);
				mav.addObject("rtAddSvcList", service.pere501_6Q(vo));
			}

			COMAVo codeVo = new COMAVo();
			//입금반환 은행
			codeVo.setCode_p_no("04");
			mav.addObject("codeList04",comaService.coma104Q(codeVo));

			PETIVo petiVo = new PETIVo();
			petiVo.setP_id(vo.getP_id());
			Map pensionInfo = petiService.peti300Q(petiVo);
			
			mav.addObject("pensionInfo",pensionInfo);
			return mav;
		}else{
			//자료를 옮기고 취소처리한다.
			if(vo.getIdxs()!=null && 0 < vo.getIdxs().length){
				for(int i=0; i<vo.getIdxs().length;i++){
					vo.setPr_no(vo.getPr_nos()[vo.getIdxs()[i]]);
					vo.setReservation_dt(vo.getReservation_dts()[vo.getIdxs()[i]]);
					service.pere600_1T(vo);
					service.pere600_2T(vo);
				}
			}
			
			if(vo.getIdxs2()!=null && 0 < vo.getIdxs2().length){
				for(int i=0; i<vo.getIdxs2().length;i++){
					vo.setAs_no(vo.getAs_nos()[vo.getIdxs2()[i]]);
					service.pere502_3T(vo);	
				}
			}
			
			Map sms_data = service.pere502_4Q(vo);
			
			//sms 보내기 시작
			//sms 보내기 
			String data =(String) sms_data.get("r_info");
			
			String into = data.split("@")[1];
			int dayCnt = 0;
			String reservation_dt="";
			String room_nm="";
			
			for(int j=0; j<into.split(";").length;j++){
				String[] vals = into.split(";")[j].split(":");
				//입금대기자 정보(부가서비스 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...

				String[] val4 = vals[4].split(",");
				for(int k =0; k<val4.length;k++){
					dayCnt++;
					
					if(k==0 && j==0){
						reservation_dt=val4[k].substring(0,4) +"."+val4[k].substring(4,6)+"."+val4[k].substring(6,8);
						room_nm=vals[0];
					}
				}
			}
			
			Map smsMap = service.pere1100Q(vo);
			SMSUtil smsUtil = new SMSUtil();
			if("Y".equals(smsMap.get("f1"))){
				//사용자에게 보내기
//				[펜션명]2009-00-00/객실명 예약취소완료
				StringBuffer msg = new StringBuffer();
				String send = sms_data.get("p_phone1")+"-"+sms_data.get("p_phone2")+"-"+sms_data.get("p_phone3");
				String recive = (String)sms_data.get("r_phone1")+"-"+(String)sms_data.get("r_phone2")+"-"+(String)sms_data.get("r_phone3");
				msg.append("[");
				msg.append(sms_data.get("p_nm"));
				msg.append("] ");
				msg.append(reservation_dt);
				if(dayCnt>1){
					msg.append("외 ");
					msg.append((dayCnt-1));
					msg.append("일");
				}
				msg.append("/");
				msg.append(room_nm);
				if(into.split(";").length>1){
					msg.append("외 ");
					msg.append((into.split(";").length-1));
					msg.append("객실");
				}
				msg.append(" 예약취소 완료");
				
				PETIVo petiVo = new PETIVo();
				petiVo.setP_id(vo.getP_id());
				Map pensionInfo = petiService.peti300Q(petiVo);
				if("Y".equals(pensionInfo.get("sms_send_yn"))){
					int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
					
					if(chk_sms_cnt > 0){

						String returnCode = smsUtil.send(send, recive, JspUtil.getByteSizeToString(msg.toString(),80));
						//sms 히스토리에 넣기
						vo.setP_nm((String) sms_data.get("p_nm") );
						vo.setFrom_no(send);
						vo.setTo_no(recive);
						vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),80));
						vo.setC_code(returnCode);
						vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
						
						service.pere710Q(vo);
						if("1".equals(returnCode)){
							//sms 카운트 줄이기
							service.pere711Q(vo);
						}
					}
				}
				
			}
			if("Y".equals(smsMap.get("f2"))){
				//관리자에게 보내기
//				[취소완료]2009-00-00/객실명/1박/아무개
				StringBuffer msg = new StringBuffer();
				String send =  (String)sms_data.get("r_phone1")+"-"+(String)sms_data.get("r_phone2")+"-"+(String)sms_data.get("r_phone3");
				String recive =sms_data.get("p_phone1")+"-"+sms_data.get("p_phone2")+"-"+sms_data.get("p_phone3");
				
				msg.append("[취소완료]");
				msg.append(reservation_dt);
				if(dayCnt>1){
					msg.append("외 ");
					msg.append((dayCnt-1));
					msg.append("일");
				}
				msg.append("/");
				msg.append(room_nm);
				if(into.split(";").length>1){
					msg.append("외 ");
					msg.append((into.split(";").length-1));
					msg.append("객실");
				}
				msg.append("/");
				msg.append(dayCnt);
				msg.append("/");
				msg.append(sms_data.get("reservation_nm"));
				
				PETIVo petiVo = new PETIVo();
				petiVo.setP_id(vo.getP_id());
				Map pensionInfo = petiService.peti300Q(petiVo);
				if("Y".equals(pensionInfo.get("sms_send_yn"))){
					int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
					
					if(chk_sms_cnt > 0){

						String returnCode = smsUtil.send(send, recive, JspUtil.getByteSizeToString(msg.toString(),80));
						//sms 히스토리에 넣기
						vo.setP_nm((String) sms_data.get("p_nm") );
						vo.setFrom_no(send);
						vo.setTo_no(recive);
						vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),80));
						vo.setC_code(returnCode);
						vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
						
						service.pere710Q(vo);
						if("1".equals(returnCode)){
							//sms 카운트 줄이기
							service.pere711Q(vo);
						}
					}
				}
			}
			//sms 보내기 종료
			
			//저장후 다른곳으로 포워딩
			mav.setViewName("/common/close");
			mav.addObject("redirect","./pere100Q.do?p_id="+vo.getP_id());
			mav.addObject("msg","예약취소 되었습니다.");

		}

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
		return mav;
	}
	
	/**
	 * 환불객실 취소 프로세스(사용자)
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere503T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView("/common/close");

		mav.addObject("redirect","./pere100Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","예약취소 환불요청 되었습니다.");
		
		List pList = new ArrayList();
		List sList = new ArrayList();
		
		if(vo.getIdxs()!=null && 0 < vo.getIdxs().length){
			for(int i=0; i<vo.getIdxs().length;i++){
				vo.setPr_no(vo.getPr_nos()[vo.getIdxs()[i]]);
				vo.setReservation_dt(vo.getReservation_dts()[vo.getIdxs()[i]]);
				Map pMap = service.pere502_1Q(vo);
				pList.add(pMap);
			}
		}
		if(vo.getIdxs2()!=null && 0 < vo.getIdxs2().length){
			for(int i=0; i<vo.getIdxs2().length;i++){
				vo.setAs_no(vo.getAs_nos()[vo.getIdxs2()[i]]);
				
				Map sMap =service.pere502_3Q(vo);	
				sList.add(sMap);

			}
		}
		
		//수수료
		int total_penalty_pay = 0;
//		총 금액
		int total_pay=0;
		
		Map refund = service.pere202_3Q(vo);
		//취소할 예약 객실목록
		
		if(pList!=null && 0<pList.size()){
			vo.setNext_dates(pList);
			List list = service.pere501_5Q(vo);
			List returnList = new ArrayList();
			if(list !=null && 0<list.size()){
				for(int i=0; i< list.size();i++){
					Map data = (Map) list.get(i);
					vo.setReg_dt((String)data.get("reg_dt"));
					vo.setReservation_dt((String)data.get("reservation_dt"));
					vo.setPr_no(Integer.parseInt(String.valueOf( data.get("pr_no"))));
					total_pay+=Integer.parseInt(String.valueOf( data.get("total_pay")));
					int dateCha = Integer.parseInt(String.valueOf( data.get("dateCha")));
					if(dateCha<0){
						dateCha=0;
					}
					if(dateCha>7){
						int per= (Integer) refund.get("general");
						int add_pay= (Integer) data.get("add_pay");
						data.put("per", per);
						int r_pay =Integer.parseInt( Long.toString( (long) (((Integer) data.get("total_pay")-(Integer) data.get("add_pay"))*(per/100.0))));
						
						//절삭 처리
						r_pay = r_pay/1000;
						r_pay = r_pay*1000;
						int penalty_pay= (Integer) data.get("total_pay")-r_pay-add_pay;
						data.put("penalty_pay", penalty_pay);
						total_penalty_pay+= r_pay+add_pay;
						vo.setPenalty_pay(penalty_pay);
					}else{
						int per= (Integer) refund.get("day_a_"+dateCha);
						int add_pay= (Integer) data.get("add_pay");
						data.put("per", per);
						int r_pay =Integer.parseInt( Long.toString( (long) (((Integer) data.get("total_pay")-(Integer) data.get("add_pay"))*(per/100.0))));
						//절삭 처리
						r_pay = r_pay/1000;
						r_pay = r_pay*1000;
						int penalty_pay= (Integer) data.get("total_pay")-r_pay-add_pay;
						data.put("penalty_pay", penalty_pay);
						total_penalty_pay+= r_pay+add_pay;
						vo.setPenalty_pay(penalty_pay);
					}
				}
			}
		}
		
		//부가서비스 목록
		if(sList!=null && 0<sList.size()){
			for(int i=0; i< sList.size();i++){
				Map data = (Map) sList.get(i);
				total_penalty_pay+= (Integer)data.get("total_pay");
				total_pay+=Integer.parseInt(String.valueOf( data.get("total_pay")));
			}
		}
//		System.out.println(1212);
		//총 금액
		vo.setTotal_pay(total_pay);
		//수수료
		vo.setPenalty_pay(total_penalty_pay);
		//최종 환불요청 자료에 넣기
		vo.setRe_no(service.pere503_4T(vo));
		List smsRms = new ArrayList();
		if(pList!=null && 0<pList.size()){
			vo.setNext_dates(pList);
			List list = service.pere501_5Q(vo);
			List returnList = new ArrayList();
			if(list !=null && 0<list.size()){
				for(int i=0; i< list.size();i++){
					Map data = (Map) list.get(i);
					smsRms.add(data.get("rm_no"));
					vo.setReservation_dt((String)data.get("reservation_dt"));
					vo.setPr_no(Integer.parseInt(String.valueOf( data.get("pr_no"))));
					int dateCha = Integer.parseInt(String.valueOf( data.get("dateCha")));
					if(dateCha<0){
						dateCha=0;
					}
					
					int per=100;
					if(dateCha>7){
						per= (Integer) refund.get("general");
					}else{
						per= (Integer) refund.get("day_a_"+dateCha);
					}
					int add_pay= (Integer) data.get("add_pay");
//					data.put("per", per);
					int r_pay =Integer.parseInt( Long.toString( (long) (((Integer) data.get("total_pay")-(Integer) data.get("add_pay"))*(per/100.0))));
					//절삭 처리
					r_pay = r_pay/1000;
					r_pay = r_pay*1000;
					int penalty_pay= r_pay+add_pay;
//					data.put("penalty_pay", penalty_pay);
//					total_penalty_pay+= r_pay+add_pay;
					vo.setPenalty_per(per);
					vo.setPenalty_pay(penalty_pay);
					
					//데이터 환불요청 후 취소자료에 넣기
					service.pere503_1T(vo);
					
				}
			}
			
			//예약객실 취소처리
			vo.setNext_dates(smsRms);
			
			//삭제전 sms 보내기

			//sms 보내기
			Map sms_data = service.pere502_4Q(vo);
			vo.setNext_dates(pList);
			
			Map smsMap = service.pere1100Q(vo);
			SMSUtil smsUtil = new SMSUtil();

			PETIVo petiVo = new PETIVo();
			petiVo.setP_id(vo.getP_id());
			Map pensionInfo = petiService.peti300Q(petiVo);
			
			
			
			if(null !=sms_data){
				//메세지 만들기
				String data =(String) sms_data.get("r_info");
				
				String into = data.split("@")[1];
				int dayCnt = 0;
				String reservation_dt="";
				String room_nm="";
				
				for(int j=0; j<into.split(";").length;j++){
					String[] vals = into.split(";")[j].split(":");
					//입금대기자 정보(부가서비스 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...

					String[] val4 = vals[4].split(",");
					for(int k =0; k<val4.length;k++){
						dayCnt++;
						if(k==0 && j==0){
							reservation_dt=val4[k].substring(0,4) +"."+val4[k].substring(4,6)+"."+val4[k].substring(6,8);
							room_nm=vals[0];
//							if(into.split(";").length>1){
//								reservation_dt+=".";
//								room_nm+=".";
//							}
						}
					}
				}
				//메세지 만들기 종료

//					[펜션명]아무개님 예약취소 완료:50.000원 익일6시이내
//					입금됩니다
				DecimalFormat decFormat = new java.text.DecimalFormat("###,###,###,###");
				
//				StringBuffer msg = new StringBuffer();
//				msg.append("[");
//				msg.append(pensionInfo.get("p_nm"));
//				msg.append("] ");
//				msg.append(sms_data.get("reservation_nm"));
//				msg.append("님 예약취소 완료 : ");
//				msg.append(decFormat.format(total_penalty_pay) );
//				msg.append("원 익일 6시이내 입금됩니다.");
				
//				if("Y".equals(smsMap.get("g1"))){
				if("Y".equals(smsMap.get("f1"))){
					//사용자에게 보내기
//					예약자	[펜션명]2009-00-00/객실명 예약취소요청		
//					
					StringBuffer msg = new StringBuffer();
					msg.append("[");
					msg.append(pensionInfo.get("p_nm"));
					msg.append("] ");
					msg.append(reservation_dt);
					if(dayCnt>1){
						msg.append("외 ");
						msg.append((dayCnt-1));
						msg.append("일");
					}
					msg.append("/");
					msg.append(room_nm);
					if(into.split(";").length>1){
						msg.append("외 ");
						msg.append((into.split(";").length-1));
						msg.append("객실");
					}
					msg.append(" 예약취소요청");
					
//					msg.append(decFormat.format(total_penalty_pay) );
//					msg.append("원 익일 6시이내 입금됩니다.");
					
					String send = pensionInfo.get("p_phone1")+"-"+pensionInfo.get("p_phone2")+"-"+pensionInfo.get("p_phone3");
					String recive =(String) sms_data.get("r_phone1")+"-"+sms_data.get("r_phone2")+"-"+sms_data.get("r_phone3");
					
					
					
					if("Y".equals(pensionInfo.get("sms_send_yn"))){
						int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
						
						if(chk_sms_cnt > 0){

							String returnCd = smsUtil.send(send, recive, JspUtil.getByteSizeToString(msg.toString(),80));
							//sms 히스토리에 넣기
							vo.setP_nm((String) pensionInfo.get("p_nm") );
							vo.setFrom_no(send);
							vo.setTo_no(recive);
							vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),80));
							vo.setC_code(returnCd);
							vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
							
							service.pere710Q(vo);
							if("1".equals(returnCd)){
								service.pere711Q(vo);
							}
							//sms 히스토리에 넣기 종료
						}
					}
					
				}
//				if("Y".equals(smsMap.get("g2"))){
				if("Y".equals(smsMap.get("f2"))){
					//관리자에게 보내기
//					관리자	[취소요청]2009-00-00/객실명/1박/아무개
					StringBuffer msg = new StringBuffer();
					msg.append("[취소요청] ");
					
					msg.append(reservation_dt);
					if(dayCnt>1){
						msg.append("외 ");
						msg.append((dayCnt-1));
						msg.append("일");
					}
					msg.append("/");
					msg.append(room_nm);
					if(into.split(";").length>1){
						msg.append("외 ");
						msg.append((into.split(";").length-1));
						msg.append("객실");
					}
					msg.append("/");
					msg.append(dayCnt);
					msg.append("박");
					msg.append("/");
					msg.append(sms_data.get("reservation_nm"));
					
					String send = (String) sms_data.get("r_phone1")+"-"+sms_data.get("r_phone2")+"-"+sms_data.get("r_phone3");
					String recive = pensionInfo.get("p_phone1")+"-"+pensionInfo.get("p_phone2")+"-"+pensionInfo.get("p_phone3");
					
					if("Y".equals(pensionInfo.get("sms_send_yn"))){
						int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
						
						if(chk_sms_cnt > 0){
							String returnCd = smsUtil.send(send, recive, JspUtil.getByteSizeToString(msg.toString(),80));
							//sms 히스토리에 넣기
							vo.setP_nm((String) pensionInfo.get("p_nm") );
							vo.setFrom_no(send);
							vo.setTo_no(recive);
							vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),80));
							vo.setC_code(returnCd);
							vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
							
							service.pere710Q(vo);
							if("1".equals(returnCd)){
								service.pere711Q(vo);
							}		
						}
					}
					
					
				}

			}
			//sms 보내기 끝
			//예약객실 삭제
			service.pere503_2T(vo);
		}
		
		//부가서비스 목록
		if(sList!=null && 0<sList.size()){
			vo.setNext_dates(sList);
			service.pere503_3T(vo);
		}
		

		
		return mav;
	}
	
	/**
	 * 예약종합정보
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere700Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("pageUrl","pere700Q.do");
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmDatedd = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();//오늘       

		String selDt = "";
		String selDtTmp = "";
		
		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			selDt = frmDate.format(d1.getTime());
			selDtTmp = frmDate.format(d1.getTime());
			vo.setReservation_dt(frmDate.format(d1.getTime())+"%");
		}else{
			selDt =vo.getReservation_dt();
			selDtTmp = vo.getReservation_dt();
			vo.setReservation_dt(vo.getReservation_dt()+"%");
		}
		mav.addObject("selDtTmp",selDtTmp);		
		if(selDt.length()==6){
			mav.addObject("selDt",selDt+"01");
		}else if(selDt.length()==8){
			mav.addObject("selDt",selDt);
		}
		
		if(null==vo.getRm_status() || "".equals(vo.getRm_status())){
			vo.setRm_status("R");
		}
		
		if(null != vo.getSrc_val() && !"".equals(vo.getSrc_val())){
			vo.setSrc_val("%"+ vo.getSrc_val() +"%");
		}
		
		
		List list = service.pere700Q(vo);
		List rList = new ArrayList();
		if(list!=null && 0<list.size()){
			for(int i =0; i< list.size();i++){
				Map map = (Map) list.get(i);
				String data =(String) map.get("r_info");
				
				//부가서비스 가격
				String add_svc = data.split("@")[0];
				
				String into = data.split("@")[1];
				int pay = 0;
				String room_nm="";
				String reg_dt="";
				String use_man_cnt="";
				String use_cnt="";
				String reservation_dt="";
				String reservation_dt_tmp="";
				String day_cnt="";
				String total_pay="";

				for(int j=0; j<into.split(";").length;j++){

					String[] vals = into.split(";")[j].split(":");
					//입금대기자 정보(부가서비스 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...
					if(j!=0){
						room_nm+="</br>";            
						reg_dt+="</br>";             
						use_man_cnt+="</br>";        
						use_cnt+="</br>";            
						reservation_dt+="</br>";     
						reservation_dt_tmp+="</br>"; 
						day_cnt+="</br>";            
						total_pay+="</br>";          
					}
					room_nm +=vals[0];

					use_man_cnt+=vals[2]+"/"+vals[3];
					
					String[] val4 = vals[4].split(",");
					for(int k =0; k<val4.length;k++){
						if(k==0){
							reservation_dt+=val4[k].substring(4,6)+"."+val4[k].substring(6,8);
						}else{
							if(val4[k-1].substring(4,6).equals(val4[k].substring(4,6)) ){
								reservation_dt+=", "+val4[k].substring(6,8);	
							}else{
								reservation_dt+=", "+val4[k-1].substring(4,6)+"."+val4[k].substring(6,8);
							}
							
						}
					}
					reservation_dt+="("+vals[1].substring(2,4)+"."+vals[1].substring(4,6)+"."+vals[1].substring(6,8)+")";

					day_cnt+=vals[5]+"박";             
					total_pay+=vals[6];           
					
					pay +=Integer.parseInt(vals[6]);
				}
				
				map.put("add_svc", add_svc);
				map.put("room_nm", room_nm);
				map.put("reg_dt", reg_dt);
				map.put("use_man_cnt", use_man_cnt);
				map.put("reservation_dt", reservation_dt);
				map.put("day_cnt", day_cnt);
				
				map.put("total_pay", (pay+Integer.parseInt(add_svc)));
				
				rList.add(map);
			}
		}
		mav.addObject("list", rList);
		mav.addObject("mapCnts", service.pere700_1Q(vo));
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
		return mav;
	}
	
	/**
	 * 입금처리
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere700T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./pere700Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","입금확인 되었습니다");

		service.pere700T(vo);
		
		
		
		return mav;
	}
	
	/**
	 * 환불요청현황
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere701Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("pageUrl","pere701Q.do");
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmDatedd = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();//오늘       

		String selDt = "";
		String selDtTmp = "";


		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			selDt = frmDate.format(d1.getTime());
			selDtTmp = frmDate.format(d1.getTime());
			vo.setReservation_dt(frmDate.format(d1.getTime())+"%");
		}else{
			selDt =vo.getReservation_dt();
			selDtTmp = vo.getReservation_dt();
			vo.setReservation_dt(vo.getReservation_dt()+"%");
		}
		mav.addObject("selDtTmp",selDtTmp);		
		if(selDt.length()==6){
			mav.addObject("selDt",selDt+"01");
		}else if(selDt.length()==8){
			mav.addObject("selDt",selDt);
		}

		if(null != vo.getSrc_val() && !"".equals(vo.getSrc_val())){
			vo.setSrc_val("%"+ vo.getSrc_val() +"%");
		}
		mav.addObject("mapCnts", service.pere700_1Q(vo));
		
		
		List list = service.pere701Q(vo);
		List rList=new ArrayList();
		
		if(list!=null && 0<list.size()){
			for(int i =0; i< list.size();i++){
				Map map = (Map) list.get(i);
				String data =(String) map.get("cancel_info");
				
				if(data==null || "".equals(data)){
					map.put("room_nm", "서비스 삭제");
					rList.add(map);
					continue;
				}
				
				//부가서비스 가격
				String add_svc = data.split("@")[0];
				
				String into = data.split("@")[1];
				int pay = 0;
				String room_nm="";
				String reg_dt="";
				String use_man_cnt="";
				String use_cnt="";
				String reservation_dt="";
				String reservation_dt_tmp="";
				String day_cnt="";
				String total_pay="";

				for(int j=0; j<into.split(";").length;j++){
					String[] vals = into.split(";")[j].split(":");
					//입금대기자 정보(부가서비스 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...
					if(j!=0){
						room_nm+="</br>";            
						reg_dt+="</br>";             
						use_man_cnt+="</br>";        
						use_cnt+="</br>";            
						reservation_dt+="</br>";     
						reservation_dt_tmp+="</br>"; 
						day_cnt+="</br>";            
						total_pay+="</br>";          
					}
					room_nm +=vals[0];

					use_man_cnt+=vals[2]+"/"+vals[3];
					
					String[] val4 = vals[4].split(",");
					for(int k =0; k<val4.length;k++){
						if(k==0){
							reservation_dt+=val4[k].substring(4,6)+"."+val4[k].substring(6,8);
						}else{
							if(val4[k-1].substring(4,6).equals(val4[k].substring(4,6)) ){
								reservation_dt+=", "+val4[k].substring(6,8);	
							}else{
								reservation_dt+=", "+val4[k-1].substring(4,6)+"."+val4[k].substring(6,8);
							}
							
						}
					}
					reservation_dt+="("+vals[1].substring(2,4)+"."+vals[1].substring(4,6)+"."+vals[1].substring(6,8)+")";

					day_cnt+=vals[5]+"박";             
					total_pay+=vals[6];           
					
					pay +=Integer.parseInt(vals[6]);
				}
				map.put("add_svc", add_svc);
				map.put("room_nm", room_nm);
				map.put("reg_dt", reg_dt);
				map.put("use_man_cnt", use_man_cnt);
				map.put("reservation_dt", reservation_dt);
				map.put("day_cnt", day_cnt);
				
				map.put("total_pay", (pay+Integer.parseInt(add_svc)));
				
				rList.add(map);
			}
		}
		mav.addObject("list", rList);
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);

		return mav;
	}
	
	/**
	 * 환불요청 조회
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere702Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();
		
		//환불요금표
		Map refund = service.pere202_3Q(vo);

		//객실예약정보 조회
		mav.addObject("list", service.pere702_1Q(vo));
		
		//부가서비스 조회
		mav.addObject("rList", service.pere702_2Q(vo));
		
		//예약자 환불정보 조회
		mav.addObject("map", service.pere702_3Q(vo));
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
		return mav;
	}
	
	
	/**
	 * 환불금 입금처리
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere702T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./pere700Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","환불금 입금처리 되었습니다");

		//환불금 처리
		service.pere702T(vo);
		
		return mav;
	}
	
	/**
	 * 종합취소현황
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere703Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("pageUrl","pere703Q.do");
		
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmDatedd = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();//오늘       

		String selDt = "";
		String selDtTmp = "";
		
		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			selDt = frmDate.format(d1.getTime());
			selDtTmp = frmDate.format(d1.getTime());
			vo.setReservation_dt(frmDate.format(d1.getTime())+"%");
		}else{
			selDt =vo.getReservation_dt();
			selDtTmp = vo.getReservation_dt();
			vo.setReservation_dt(vo.getReservation_dt()+"%");
		}
		mav.addObject("selDtTmp",selDtTmp);		
		if(selDt.length()==6){
			mav.addObject("selDt",selDt+"01");
		}else if(selDt.length()==8){
			mav.addObject("selDt",selDt);
		}
		//조회조건
		if(null != vo.getSrc_val() && !"".equals(vo.getSrc_val())){
			vo.setSrc_val("%"+ vo.getSrc_val() +"%");
		}
		
		//종합취소 현황조회
		List list = service.pere703Q(vo);
		List rList=new ArrayList();
		
		if(list!=null && 0<list.size()){
			for(int i =0; i< list.size();i++){
				Map map = (Map) list.get(i);
				String data =(String) map.get("cancel_info");
				
				if(data==null || "".equals(data)){
					map.put("room_nm", "서비스 삭제");
					rList.add(map);
					continue;
				}
				
				//부가서비스 가격
				String add_svc = data.split("@")[0];
				
				String into = data.split("@")[1];
				int pay = 0;
				String room_nm="";
				String reg_dt="";
				String use_man_cnt="";
				String use_cnt="";
				String reservation_dt="";
				String reservation_dt_tmp="";
				String day_cnt="";
				String total_pay="";

				for(int j=0; j<into.split(";").length;j++){
					String[] vals = into.split(";")[j].split(":");
					//입금대기자 정보(부가서비스 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...
					if(j!=0){
						room_nm+="</br>";            
						reg_dt+="</br>";             
						use_man_cnt+="</br>";        
						use_cnt+="</br>";            
						reservation_dt+="</br>";     
						reservation_dt_tmp+="</br>"; 
						day_cnt+="</br>";            
						total_pay+="</br>";          
					}
					room_nm +=vals[0];

					use_man_cnt+=vals[2]+"/"+vals[3];
					
					String[] val4 = vals[4].split(",");
					for(int k =0; k<val4.length;k++){
						if(k==0){
							reservation_dt+=val4[k].substring(4,6)+"."+val4[k].substring(6,8);
						}else{
							if(val4[k-1].substring(4,6).equals(val4[k].substring(4,6)) ){
								reservation_dt+=", "+val4[k].substring(6,8);	
							}else{
								reservation_dt+=", "+val4[k-1].substring(4,6)+"."+val4[k].substring(6,8);
							}
							
						}
					}
					reservation_dt+="("+vals[1].substring(2,4)+"."+vals[1].substring(4,6)+"."+vals[1].substring(6,8)+")";

					day_cnt+=vals[5]+"박";             
					total_pay+=vals[6];           
					
					pay +=Integer.parseInt(vals[6]);
				}
				map.put("add_svc", add_svc);
				map.put("room_nm", room_nm);
				map.put("reg_dt", reg_dt);
				map.put("use_man_cnt", use_man_cnt);
				map.put("reservation_dt", reservation_dt);
				map.put("day_cnt", day_cnt);
				
				map.put("total_pay", (pay+Integer.parseInt(add_svc)));
				
				
				rList.add(map);
			}
		}
		mav.addObject("list", rList);

		mav.addObject("mapCnts", service.pere700_1Q(vo));
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);

		return mav;
	}
	
	/**
	 * 종합취소 미입금 취소 삭제 처리
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere703T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {

		String reservation_dt = vo.getReservation_dt()==null?"":vo.getReservation_dt();
		ModelAndView mav = new ModelAndView("redirect:./pere703Q.do?p_id="+vo.getP_id()+"&reservation_dt="+reservation_dt);
		service.pere703T(vo);
		return mav;
	}
	
	/**
	 * 예약종료 현황
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere704Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("pageUrl","pere704Q.do");
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmDatedd = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();//오늘       

		String selDt = "";
		String selDtTmp = "";
		
		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			selDt = frmDate.format(d1.getTime());
			selDtTmp = frmDate.format(d1.getTime());
			vo.setReservation_dt(frmDate.format(d1.getTime())+"%");
		}else{
			selDt =vo.getReservation_dt();
			selDtTmp = vo.getReservation_dt();
			vo.setReservation_dt(vo.getReservation_dt()+"%");
		}
		mav.addObject("selDtTmp",selDtTmp);		
		if(selDt.length()==6){
			mav.addObject("selDt",selDt+"01");
		}else if(selDt.length()==8){
			mav.addObject("selDt",selDt);
		}
		//조회조건
		if(null != vo.getSrc_val() && !"".equals(vo.getSrc_val())){
			vo.setSrc_val("%"+ vo.getSrc_val() +"%");
		}

		
		List list = service.pere704Q(vo);
		List rList=new ArrayList();
		
		if(list!=null && 0<list.size()){
			for(int i =0; i< list.size();i++){
				Map map = (Map) list.get(i);
				String data =(String) map.get("com_info");
				
				if(data==null || "".equals(data)){
					map.put("room_nm", "서비스 삭제");
					rList.add(map);
					continue;
				}
				
				//부가서비스 가격
				String add_svc = data.split("@")[0];
				
				String into = data.split("@")[1];
				int pay = 0;
				String room_nm="";
				String reg_dt="";
				String use_man_cnt="";
				String use_cnt="";
				String reservation_dt="";
				String reservation_dt_tmp="";
				String day_cnt="";
				String total_pay="";

				for(int j=0; j<into.split(";").length;j++){
					String[] vals = into.split(";")[j].split(":");
					//입금대기자 정보(부가서비스 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...
					if(j!=0){
						room_nm+="</br>";            
						reg_dt+="</br>";             
						use_man_cnt+="</br>";        
						use_cnt+="</br>";            
						reservation_dt+="</br>";     
						reservation_dt_tmp+="</br>"; 
						day_cnt+="</br>";            
						total_pay+="</br>";          
					}
					room_nm +=vals[0];
					use_man_cnt+=vals[2]+"/"+vals[3];         
					String[] val4 = vals[4].split(",");
					for(int k =0; k<val4.length;k++){
						if(k==0){
							reservation_dt+=val4[k].substring(4,6)+"."+val4[k].substring(6,8);
						}else{
							if(val4[k-1].substring(4,6).equals(val4[k].substring(4,6)) ){
								reservation_dt+=", "+val4[k].substring(6,8);	
							}else{
								reservation_dt+=", "+val4[k-1].substring(4,6)+"."+val4[k].substring(6,8);
							}
							
						}
					}
					reservation_dt+="("+vals[1].substring(2,4)+"."+vals[1].substring(4,6)+"."+vals[1].substring(6,8)+")";

					day_cnt+=vals[5]+"박";             
					total_pay+=vals[6];           
					
					pay +=Integer.parseInt(vals[6]);
				}
				
				map.put("add_svc", add_svc);
				map.put("room_nm", room_nm);
				map.put("reg_dt", reg_dt);
				map.put("use_man_cnt", use_man_cnt);
//				map.put("use_cnt", use_cnt);
				map.put("reservation_dt", reservation_dt);
//				map.put("reservation_end_dt", reservation_dt_tmp);
				map.put("day_cnt", day_cnt);
				
				map.put("total_pay", (pay+Integer.parseInt(add_svc)));
				
				rList.add(map);
			}
		}
		mav.addObject("list", rList);
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);

		mav.addObject("mapCnts", service.pere700_1Q(vo));
		return mav;
	}
	
	/**
	 * 예약완료자료 삭제
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere704T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {

		String reservation_dt = vo.getReservation_dt()==null?"":vo.getReservation_dt();
		ModelAndView mav = new ModelAndView("redirect:./pere704Q.do?p_id="+vo.getP_id()+"&reservation_dt="+reservation_dt);
		service.pere704T(vo);
		return mav;
	}
	
	
	
	/**
	 * 입금대기현황 상세
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere705Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();
		vo.setRm_status("R");
		
		List list = (List) service.pere705Q(vo);
		List returnList = new ArrayList();
		if(list !=null && 0<list.size()){
			for(int i=0; i < list.size();i++){
				Map data = (Map) list.get(i);
//				
//				data.put("dc_pay", 0);
//				data.put("pay", 0);
				
				returnList.add(data);
			}
		}
		
//		
		mav.addObject("list", returnList);
		mav.addObject("rtAddSvcList", service.pere705_1Q(vo));
		
		//예약자 정보
		mav.addObject("reservationInfo", service.pere705_2Q(vo));
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
		
		return mav;
	}
	
	/**
	 * 예약취소(관리자)
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere705_1T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./pere700Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","예약취소되었습니다");

		
		if(vo.getIdxs()!=null && 0 < vo.getIdxs().length){
			for(int i=0; i<vo.getIdxs().length;i++){
				vo.setPr_no(vo.getPr_nos()[vo.getIdxs()[i]]);
				vo.setReservation_dt(vo.getReservation_dts()[vo.getIdxs()[i]]);
				service.pere600_1T(vo);
				service.pere600_2T(vo);
			}
		}
		
		if(vo.getIdxs2()!=null && 0 < vo.getIdxs2().length){
			for(int i=0; i<vo.getIdxs2().length;i++){
				vo.setAs_no(vo.getAs_nos()[vo.getIdxs2()[i]]);
				service.pere502_3T(vo);	
			}
		}


		Map sms_data = service.pere502_4Q(vo);
		
		//sms 보내기 시작
		//sms 보내기 
		String data =(String) sms_data.get("r_info");
		
		String into = data.split("@")[1];
		int dayCnt = 0;
		String reservation_dt="";
		String room_nm="";
		
		for(int j=0; j<into.split(";").length;j++){
			String[] vals = into.split(";")[j].split(":");
			//입금대기자 정보(부가서비스 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...

			String[] val4 = vals[4].split(",");
			for(int k =0; k<val4.length;k++){
				dayCnt++;
				
				if(k==0 && j==0){
					reservation_dt=val4[k].substring(0,4) +"."+val4[k].substring(4,6)+"."+val4[k].substring(6,8);
					room_nm=vals[0];
//					if(into.split(";").length>1){
//						reservation_dt+=".";
//						room_nm+=".";
//					}
				}
			}
		}
		
		Map smsMap = service.pere1100Q(vo);
		SMSUtil smsUtil = new SMSUtil();
		if("Y".equals(smsMap.get("m1"))){
			//사용자에게 보내기
//			[펜션명]2009-00-00/객실명 예약취소완료
			StringBuffer msg = new StringBuffer();
			String send = sms_data.get("p_phone1")+"-"+sms_data.get("p_phone2")+"-"+sms_data.get("p_phone3");
			String recive = (String)sms_data.get("r_phone1")+"-"+(String)sms_data.get("r_phone2")+"-"+(String)sms_data.get("r_phone3");
			msg.append("[");
			msg.append(sms_data.get("p_nm"));
			msg.append("] ");
			msg.append(reservation_dt);
			if(dayCnt>1){
				msg.append("외 ");
				msg.append((dayCnt-1));
				msg.append("일");
			}
			msg.append("/");
			msg.append(room_nm);
			if(into.split(";").length>1){
				msg.append("외 ");
				msg.append((into.split(";").length-1));
				msg.append("객실");
			}
			msg.append(" 예약취소 완료");
			
			PETIVo petiVo = new PETIVo();
			petiVo.setP_id(vo.getP_id());
			Map pensionInfo = petiService.peti300Q(petiVo);
			if("Y".equals(pensionInfo.get("sms_send_yn"))){
				int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
				
				if(chk_sms_cnt > 0){
					String returnCode = smsUtil.send(send, recive, JspUtil.getByteSizeToString(msg.toString(),80));
					//sms 히스토리에 넣기
					vo.setP_nm((String) sms_data.get("p_nm") );
					vo.setFrom_no(send);
					vo.setTo_no(recive);
					vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),80));
					vo.setC_code(returnCode);
					vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
					
					service.pere710Q(vo);
					if("1".equals(returnCode)){
						//sms 카운트 줄이기
						service.pere711Q(vo);
					}
				}
			}
			
		}
		if("Y".equals(smsMap.get("m2"))){
			//관리자에게 보내기
//			[취소완료]2009-00-00/객실명/1박/아무개
			StringBuffer msg = new StringBuffer();
			String send =  (String)sms_data.get("r_phone1")+"-"+(String)sms_data.get("r_phone2")+"-"+(String)sms_data.get("r_phone3");
			String recive =sms_data.get("p_phone1")+"-"+sms_data.get("p_phone2")+"-"+sms_data.get("p_phone3");
			msg.append("[취소완료]");

			msg.append(reservation_dt);
			if(dayCnt>1){
				msg.append("외 ");
				msg.append((dayCnt-1));
				msg.append("일");
			}
			msg.append("/");
			msg.append(room_nm);
			if(into.split(";").length>1){
				msg.append("외 ");
				msg.append((into.split(";").length-1));
				msg.append("객실");
			}
			msg.append("/");
			msg.append(dayCnt);
			msg.append("박/");
			msg.append(sms_data.get("reservation_nm"));
			
			PETIVo petiVo = new PETIVo();
			petiVo.setP_id(vo.getP_id());
			Map pensionInfo = petiService.peti300Q(petiVo);
			if("Y".equals(pensionInfo.get("sms_send_yn"))){
				int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
				
				if(chk_sms_cnt > 0){

					String returnCode = smsUtil.send(send, recive, JspUtil.getByteSizeToString(msg.toString(),80));
					//sms 히스토리에 넣기
					vo.setP_nm((String) sms_data.get("p_nm") );
					vo.setFrom_no(send);
					vo.setTo_no(recive);
					vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),80));
					vo.setC_code(returnCode);
					vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
					
					service.pere710Q(vo);
					if("1".equals(returnCode)){
						//sms 카운트 줄이기
						service.pere711Q(vo);
					}		
				}
			}
			
		}
		return mav;
	}
	
	/**
	 * 입금처리
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere705_2T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./pere700Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","입금처리되었습니다");


//		List list = (List) service.pere705Q(vo);
//		long[] rm_nos = new long[list.size()];
//		
//		
//		if(list !=null && 0<list.size()){
//			for(int i=0; i < list.size();i++){
//				
//				Map data = (Map) list.get(i);
//				rm_nos[i]=Integer.parseInt(String.valueOf( data.get("rm_no")));
//
//			}
//			vo.setRm_nos(rm_nos);
//		}
		
		service.pere700T(vo);
		
		return mav;
	}	
	
	/**
	 * 대기시간 연장
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere705_3T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./pere700Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","대기시간 연장되었습니다");
		

		service.pere705_3T(vo);
		service.pere705_4T(vo);
		
		return mav;
	}	
	
	
	/**
	 *  sms 계좌 재전송
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere705_5T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		
		Map map = service.pere705_5Q(vo);
		
		StringBuffer msg = new StringBuffer();
		int totalPay=0;
		
		String r_info ="";
		
		if("".equals(map.get("r_info"))){
			r_info =(String) map.get("c_info");
		}else{
			r_info =(String) map.get("r_info");
		}
		
		
		//부가서비스 가격
		String add_svc = r_info.split("@")[0];
		String into = r_info.split("@")[1];
		int pay = 0;
		for(int j=0; j<into.split(";").length;j++){
			String[] vals = into.split(";")[j].split(":");
			pay +=Integer.parseInt(vals[6]);
		}
		
		totalPay=(pay+Integer.parseInt(add_svc));
		
//		[펜션명]객실명-국민은행 142313-123-123132 100,000원
//		30분후 예약이 자동삭제됩니다
		java.text.DecimalFormat decFormat = new java.text.DecimalFormat("###,###,###,###");
		
		msg.append("[");
		msg.append(map.get("p_nm"));
		msg.append("] ");
		msg.append(map.get("room_nm"));
		msg.append("-");
		msg.append(map.get("send_bank"));
		msg.append(" ");
		msg.append(decFormat.format(totalPay));
		msg.append("원");
		msg.append("30분후 예약이 자동취소됩니다");
		SMSUtil smsUtil = new SMSUtil();
		
		//사용자 sms 전송
		String send = map.get("p_tel1")+""+map.get("p_tel2")+map.get("p_tel3");
		String recive = map.get("r_phone1")+""+map.get("r_phone2")+map.get("r_phone3");

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		if("Y".equals(pensionInfo.get("sms_send_yn"))){
			int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
			
			if(chk_sms_cnt > 0){
				String returnCode = smsUtil.send(send, recive, msg.toString());
				//sms 히스토리에 넣기
				vo.setP_nm((String) map.get("p_nm") );
				vo.setFrom_no(send);
				vo.setTo_no(recive);
				vo.setSms_content(msg.toString());
				vo.setC_code(returnCode);
				vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
				
				service.pere710Q(vo);
				if("1".equals(returnCode)){
					//sms 카운트 줄이기
					service.pere711Q(vo);
					jsonMap.put("sendYN", "Y");
				}else{
					jsonMap.put("sendYN", "N");	
				}
				
			}
		}
		
		
		
//		jsonMap.put("", "");
//		jsonMap.put("", "");
		
		mav.addObject("map", jsonMap);
		
		
		
		return mav;
	}	
	
	
	/**
	 * 입금확인 상세화면
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere706Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();

		vo.setRm_status("C");
		List list = service.pere705Q(vo);
		List returnList = new ArrayList();
		
		Calendar nowDate = Calendar.getInstance();//오늘
		nowDate.set(Calendar.HOUR_OF_DAY, 1);
		nowDate.set(Calendar.MINUTE, 1);
		nowDate.set(Calendar.SECOND, 1);
		
		boolean cancelBtn = true;
		for(int i = 0; i < list.size();i++){
			Map map =(Map) list.get(i);
			Calendar reservationDt = Calendar.getInstance();//오늘
			String reservation_dt =(String) map.get("reservation_dt"); 
			int yyyy = Integer.parseInt(reservation_dt.substring(0,4)) ;
			int mm = Integer.parseInt(reservation_dt.substring(4,6)) ;
			int dd = Integer.parseInt(reservation_dt.substring(6,8)) ;
			reservationDt.set(yyyy,mm-1,dd,1,1,1);
						
			if((nowDate.getTime().getTime()-reservationDt.getTime().getTime())>0){
				map.put("cancelYN", "N");
			}else{
				cancelBtn=false;
				map.put("cancelYN", "Y");
			}
			returnList.add(map);
		}
		mav.addObject("list", returnList);
		mav.addObject("rtAddSvcList", service.pere705_1Q(vo));
		
		//예약자 정보
		mav.addObject("reservationInfo", service.pere705_2Q(vo));
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
		
		COMAVo codeVo = new COMAVo();
		//입금반환 은행
		codeVo.setCode_p_no("04");
		mav.addObject("codeList04",comaService.coma104Q(codeVo));
		mav.addObject("cancelBtn",cancelBtn);
		
		
		return mav;
	}
	
	/**
	 * 예약취소 환불요청으로 보냄(관리자)
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere706_1T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./pere700Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","예약취소 환불요청 되었습니다.");
		
		List pList = new ArrayList();
		List sList = new ArrayList();
		
		
		
		if(vo.getIdxs()!=null && 0 < vo.getIdxs().length){
			for(int i=0; i<vo.getIdxs().length;i++){
				vo.setPr_no(vo.getPr_nos()[vo.getIdxs()[i]]);
				vo.setReservation_dt(vo.getReservation_dts()[vo.getIdxs()[i]]);
				Map pMap = service.pere502_1Q(vo);
				pList.add(pMap);
			}
		}
		if(vo.getIdxs2()!=null && 0 < vo.getIdxs2().length){
			for(int i=0; i<vo.getIdxs2().length;i++){
				vo.setAs_no(vo.getAs_nos()[vo.getIdxs2()[i]]);
				
				Map sMap =service.pere502_3Q(vo);	
				sList.add(sMap);

			}
		}
		
		//수수료
		int total_penalty_pay = 0;
//		총 금액
		int total_pay=0;
		
		Map refund = service.pere202_3Q(vo);
		//취소할 예약 객실목록
		
		if(pList!=null && 0<pList.size()){
			vo.setNext_dates(pList);
			List list = service.pere501_5Q(vo);
			List returnList = new ArrayList();
			if(list !=null && 0<list.size()){
				for(int i=0; i< list.size();i++){
					Map data = (Map) list.get(i);
					vo.setReservation_dt((String)data.get("reservation_dt"));
					vo.setPr_no(Integer.parseInt(String.valueOf( data.get("pr_no"))));
					total_pay+=Integer.parseInt(String.valueOf( data.get("total_pay")));
					vo.setReg_dt((String)data.get("reg_dt"));
					int dateCha = Integer.parseInt(String.valueOf( data.get("dateCha")));
					if(dateCha<0){
						dateCha=0;
					}
					if(dateCha>7){
						int penalty_pay= (Integer) data.get("total_pay");
						data.put("penalty_pay",penalty_pay );
						total_penalty_pay+= penalty_pay;
						vo.setPenalty_pay(penalty_pay);
					}else{
						int per= (Integer) refund.get("day_a_"+dateCha);
						int add_pay= (Integer) data.get("add_pay");
						data.put("per", per);
						int r_pay =Integer.parseInt( Long.toString( (long) (((Integer) data.get("total_pay")-(Integer) data.get("add_pay"))*(per/100.0))));
						//절삭 처리
						r_pay = r_pay/1000;
						r_pay = r_pay*1000;
						int penalty_pay= (Integer) data.get("total_pay")-r_pay-add_pay;
						data.put("penalty_pay", penalty_pay);
						total_penalty_pay+= r_pay+add_pay;
						vo.setPenalty_pay(penalty_pay);
					}
					
					//데이터 환불요청 후 취소자료에 넣기
//					service.pere503_1T(vo);
					
				}
			}
//			
//			//예약객실 취소처리
//			vo.setNext_dates(pList);
//			//예약객실 삭제
//			service.pere503_2T(vo);
		}
		
		
		//부가서비스 목록
		if(sList!=null && 0<sList.size()){
			for(int i=0; i< sList.size();i++){
				Map data = (Map) sList.get(i);
				total_penalty_pay+= (Integer)data.get("total_pay");
				total_pay+=Integer.parseInt(String.valueOf( data.get("total_pay")));
			}
//			vo.setNext_dates(sList);
//			service.pere503_3T(vo);
			
		}
		
		//총 금액
		vo.setTotal_pay(total_pay);
		//수수료
		vo.setPenalty_pay(total_penalty_pay);
		//최종 환불요청 자료에 넣기
		vo.setRe_no(service.pere503_4T(vo));
		
		if(pList!=null && 0<pList.size()){
			vo.setNext_dates(pList);
			List list = service.pere501_5Q(vo);
			List returnList = new ArrayList();
			if(list !=null && 0<list.size()){
				for(int i=0; i< list.size();i++){
					Map data = (Map) list.get(i);
					vo.setReservation_dt((String)data.get("reservation_dt"));
					vo.setPr_no(Integer.parseInt(String.valueOf( data.get("pr_no"))));
					int dateCha = Integer.parseInt(String.valueOf( data.get("dateCha")));
					if(dateCha<0){
						dateCha=0;
					}
					
					int per=100;
					if(dateCha>7){
						per= (Integer) refund.get("general");
					}else{
						per= (Integer) refund.get("day_a_"+dateCha);
					}
					int add_pay= (Integer) data.get("add_pay");
//					data.put("per", per);
					int r_pay =Integer.parseInt( Long.toString( (long) (((Integer) data.get("total_pay")-(Integer) data.get("add_pay"))*(per/100.0))));
					//절삭 처리
					r_pay = r_pay/1000;
					r_pay = r_pay*1000;
					int penalty_pay= r_pay+add_pay;
//					data.put("penalty_pay", penalty_pay);
//					total_penalty_pay+= r_pay+add_pay;
					vo.setPenalty_per(per);
					vo.setPenalty_pay(penalty_pay);
					
					//데이터 환불요청 후 취소자료에 넣기
					service.pere503_1T(vo);
					
				}
			}
			
			//예약객실 취소처리
			vo.setNext_dates(pList);
			//예약객실 삭제
			service.pere503_2T(vo);
		}
		
		
		
		//부가서비스 목록
		if(sList!=null && 0<sList.size()){
			vo.setNext_dates(sList);
			service.pere503_3T(vo);
		}
		
		List rm_nos = new ArrayList();
		for(int i =0; i< pList.size() ;i++){
			Map data1 = (Map) pList.get(i);
			rm_nos.add(	data1.get("rm_no"));
		}
		vo.setNext_dates(rm_nos);
		
		//sms 보내기
		List smsList = service.pere700_2Q(vo);
		vo.setNext_dates(pList);
		
		Map smsMap = service.pere1100Q(vo);
		SMSUtil smsUtil = new SMSUtil();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		if(null !=smsList && 0<smsList.size()){
			for(int i =0;i<smsList.size();i++){
				Map map = (Map) smsList.get(i);
				

//				[펜션명]아무개님 예약취소 완료:50.000원 익일6시이내
//				입금됩니다
				DecimalFormat decFormat = new java.text.DecimalFormat("###,###,###,###");
				
				StringBuffer msg = new StringBuffer();
				msg.append("[");
				msg.append(pensionInfo.get("p_nm"));
				msg.append("] ");
				msg.append(map.get("reservation_nm"));
				msg.append("님 예약취소 완료 : ");
				msg.append(decFormat.format(vo.getTotal_pay()) );
				msg.append("원 익일 6시이내 입금됩니다.");
				
				
				
				if("Y".equals(pensionInfo.get("sms_send_yn"))){
					int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
					
					if(chk_sms_cnt > 0){

						if("Y".equals(smsMap.get("n1"))){
							//사용자에게 보내기
							
							String send = pensionInfo.get("p_phone1")+"-"+pensionInfo.get("p_phone2")+"-"+pensionInfo.get("p_phone3");
							String recive = map.get("r_phone1")+"-"+map.get("r_phone2")+"-"+map.get("r_phone3");

							String returnCd = smsUtil.send(send, recive, JspUtil.getByteSizeToString(msg.toString(),80));
							//sms 히스토리에 넣기
							vo.setP_nm((String) pensionInfo.get("p_nm") );
							vo.setFrom_no(send);
							vo.setTo_no(recive);
							vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),80));
							vo.setC_code(returnCd);
							vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
							
							service.pere710Q(vo);
							if("1".equals(returnCd)){
								service.pere711Q(vo);
							}
							//sms 히스토리에 넣기 종료
						}
						if("Y".equals(smsMap.get("n2"))){
							//관리자에게 보내기
							String send = map.get("r_phone1")+"-"+map.get("r_phone2")+"-"+map.get("r_phone3");
							String recive = pensionInfo.get("p_phone1")+"-"+pensionInfo.get("p_phone2")+"-"+pensionInfo.get("p_phone3");
							
							String returnCd = smsUtil.send(send, recive, JspUtil.getByteSizeToString(msg.toString(),80));
							//sms 히스토리에 넣기
							vo.setP_nm((String) pensionInfo.get("p_nm") );
							vo.setFrom_no(send);
							vo.setTo_no(recive);
							vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),80));
							vo.setC_code(returnCd);
							vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
							
							service.pere710Q(vo);
							if("1".equals(returnCd)){
								service.pere711Q(vo);
							}
						}		
					}
				}
				
			}	
		}
		//sms 보내기 끝
		
		
		return mav;
	}	
	
	/**
	 * 예약대기 변경
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere706_2T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./pere700Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","예약대기 처리되었습니다");
		

		service.pere706_1T(vo);
		service.pere706_2T(vo);
		
		return mav;
	}	
	
	
	/**
	 * 예약취소 예약자 번호로 예약취소하기(관리자 )
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere706_3T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./pere700Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","예약취소 되었습니다.");
		
		if(!"C".equals(vo.getRm_status())){
			vo.setRm_status("R");
		}
		
		if(vo.getRm_nos()!=null && vo.getRm_nos().length>0){
			for(int jj =0; jj< vo.getRm_nos().length;jj++){

				vo.setRm_no(vo.getRm_nos()[jj]);
				
				List pList = new ArrayList();
				List sList = new ArrayList();
				
				boolean chkRefunds = false;
				
				List roomsList = service.pere706_3_1Q(vo);
				if(roomsList !=null && 0<roomsList.size()){
					for(int i=0; i< roomsList.size();i++){
						Map pMap = (Map) roomsList.get(i);
						String rm_status =(String) pMap.get("rm_status");
						if("C".equals(rm_status)){
							chkRefunds=true;
						}
						pList.add(pMap);
					}
				}
				
				List serviceList = service.pere706_3_2Q(vo);
				if(serviceList !=null && 0<serviceList.size()){
					for(int i=0; i< serviceList.size();i++){
						Map sMap = (Map) serviceList.get(i);
						
						sList.add(sMap);
					}
				}
				
				if(chkRefunds){
					//환불 객실취소
					//수수료
					int total_penalty_pay = 0;
//					총 금액
					int total_pay=0;
					
					Map refund = service.pere202_3Q(vo);
					//취소할 예약 객실목록
					
					if(pList!=null && 0<pList.size()){
						vo.setNext_dates(pList);
						List list = service.pere501_5Q(vo);
						List returnList = new ArrayList();
						if(list !=null && 0<list.size()){
							for(int i=0; i< list.size();i++){
								Map data = (Map) list.get(i);
								vo.setReservation_dt((String)data.get("reservation_dt"));
								vo.setPr_no(Integer.parseInt(String.valueOf( data.get("pr_no"))));
								total_pay+=Integer.parseInt(String.valueOf( data.get("total_pay")));
								int dateCha = Integer.parseInt(String.valueOf( data.get("dateCha")));
								if(dateCha<0){
									dateCha=0;
								}
								if(dateCha>7){
									int penalty_pay= (Integer) data.get("total_pay");
									data.put("penalty_pay",penalty_pay );
									total_penalty_pay+= penalty_pay;
									vo.setPenalty_pay(penalty_pay);
								}else{
									int per= (Integer) refund.get("day_a_"+dateCha);
									int add_pay= (Integer) data.get("add_pay");
									data.put("per", per);
									int r_pay =Integer.parseInt( Long.toString( (long) (((Integer) data.get("total_pay")-(Integer) data.get("add_pay"))*(per/100.0))));
									//절삭 처리
									r_pay = r_pay/1000;
									r_pay = r_pay*1000;
									int penalty_pay= (Integer) data.get("total_pay")-r_pay-add_pay;
									data.put("penalty_pay", penalty_pay);
									total_penalty_pay+= r_pay+add_pay;
									vo.setPenalty_pay(penalty_pay);
								}
								
								//데이터 환불요청 후 취소자료에 넣기
//								service.pere503_1T(vo);
								
							}
						}
//						
//						//예약객실 취소처리
//						vo.setNext_dates(pList);
//						//예약객실 삭제
//						service.pere503_2T(vo);
					}
					
					
					//부가서비스 목록
					if(sList!=null && 0<sList.size()){
						for(int i=0; i< sList.size();i++){
							Map data = (Map) sList.get(i);
							String as_status = (String) data.get("as_status");
							if("C".equals(as_status)){
								total_penalty_pay+= (Integer)data.get("total_pay");
								total_pay+=Integer.parseInt(String.valueOf( data.get("total_pay")));	
							}
						}
					}
					
					//총 금액
					vo.setTotal_pay(total_pay);
					//수수료
					vo.setPenalty_pay(total_penalty_pay);
					//최종 환불요청 자료에 넣기
					vo.setRe_no(service.pere503_4T(vo));
					
					if(pList!=null && 0<pList.size()){
						vo.setNext_dates(pList);
						List list = service.pere501_5Q(vo);
						List returnList = new ArrayList();
						if(list !=null && 0<list.size()){
							for(int i=0; i< list.size();i++){
								Map data = (Map) list.get(i);
								vo.setReservation_dt((String)data.get("reservation_dt"));
								vo.setPr_no(Integer.parseInt(String.valueOf( data.get("pr_no"))));
								int dateCha = Integer.parseInt(String.valueOf( data.get("dateCha")));
								if(dateCha<0){
									dateCha=0;
								}
								
								int per=100;
								if(dateCha>7){
									per= (Integer) refund.get("general");
								}else{
									per= (Integer) refund.get("day_a_"+dateCha);
								}
								int add_pay= (Integer) data.get("add_pay");
//								data.put("per", per);
								int r_pay =Integer.parseInt( Long.toString( (long) (((Integer) data.get("total_pay")-(Integer) data.get("add_pay"))*(per/100.0))));
								//절삭 처리
								r_pay = r_pay/1000;
								r_pay = r_pay*1000;
								int penalty_pay= r_pay+add_pay;
								vo.setPenalty_per(per);
								vo.setPenalty_pay(penalty_pay);
								
								//데이터 환불요청 후 취소자료에 넣기
								service.pere503_1T(vo);
								
							}
						}
						//예약객실 취소처리
						vo.setNext_dates(pList);
						//예약객실 삭제
						service.pere503_2T(vo);
					}
					
					//부가서비스 목록
					if(sList!=null && 0<sList.size()){
						vo.setNext_dates(sList);
						service.pere503_3T(vo);
					}
				}else{
					//미입금 객실 취소
					
					Map sms_data = service.pere706_3_3Q(vo);
					
					//자료를 옮기고 취소처리한다.
					if(pList!=null && 0<pList.size()){
						for(int i=0; i<pList.size();i++){
							Map data = (Map) pList.get(i);
							
							vo.setPr_no((Integer)data.get("pr_no"));
							vo.setReservation_dt((String)data.get("reservation_dt"));
							service.pere600_1T(vo);
							service.pere600_2T(vo);
						}
					}
					
					if(sList!=null && 0<sList.size()){
						for(int i=0; i<sList.size();i++){
							Map data = (Map) sList.get(i);
							
							vo.setAs_no((Integer)data.get("as_no"));
							service.pere502_3T(vo);
						}
					}
					
					//sms 보내기 
					String data =(String) sms_data.get("r_info");
					
					String into = data.split("@")[1];
					int dayCnt = 0;
					String reservation_dt="";
					String room_nm="";
					
					for(int j=0; j<into.split(";").length;j++){
						String[] vals = into.split(";")[j].split(":");
						//입금대기자 정보(부가서비스 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...

						String[] val4 = vals[4].split(",");
						for(int k =0; k<val4.length;k++){
							dayCnt++;
							
							if(k==0 && j==0){
								reservation_dt=val4[k].substring(0,4) +"."+val4[k].substring(4,6)+"."+val4[k].substring(6,8);
								room_nm=vals[0];
//								if(into.split(";").length>1){
//									reservation_dt+=".";
//									room_nm+=".";
//								}
							}
						}
					}
					
					Map smsMap = service.pere1100Q(vo);
					SMSUtil smsUtil = new SMSUtil();
					
					PETIVo petiVo = new PETIVo();
					petiVo.setP_id(vo.getP_id());
					Map pensionInfo = petiService.peti300Q(petiVo);
					if("Y".equals(pensionInfo.get("sms_send_yn"))){
						int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
						
						if(chk_sms_cnt > 0){

							if("Y".equals(smsMap.get("m1"))){
								//사용자에게 보내기
//								[펜션명]2009-00-00/객실명 예약취소완료
								StringBuffer msg = new StringBuffer();
								String send = sms_data.get("p_phone1")+"-"+sms_data.get("p_phone2")+"-"+sms_data.get("p_phone3");
								String recive = (String)sms_data.get("r_phone1")+"-"+(String)sms_data.get("r_phone2")+"-"+(String)sms_data.get("r_phone3");
								msg.append("[");
								msg.append(sms_data.get("p_nm"));
								msg.append("] ");
								msg.append(reservation_dt);
								if(dayCnt>1){
									msg.append("외 ");
									msg.append((dayCnt-1));
									msg.append("일");
								}
								msg.append("/");
								msg.append(room_nm);
								if(into.split(";").length>1){
									msg.append("외 ");
									msg.append((into.split(";").length-1));
									msg.append("객실");
								}
								msg.append(" 예약취소 완료");
								
								String returnCode = smsUtil.send(send, recive, JspUtil.getByteSizeToString(msg.toString(),80));
								//sms 히스토리에 넣기
								vo.setP_nm((String) sms_data.get("p_nm") );
								vo.setFrom_no(send);
								vo.setTo_no(recive);
								vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),80));
								vo.setC_code(returnCode);
								vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
								
								service.pere710Q(vo);
								if("1".equals(returnCode)){
									//sms 카운트 줄이기
									service.pere711Q(vo);
								}
							}
							if("Y".equals(smsMap.get("m2"))){
								//관리자에게 보내기
//								[취소완료]2009-00-00/객실명/1박/아무개
								StringBuffer msg = new StringBuffer();
								String send =  (String)sms_data.get("r_phone1")+"-"+(String)sms_data.get("r_phone2")+"-"+(String)sms_data.get("r_phone3");
								String recive =sms_data.get("p_phone1")+"-"+sms_data.get("p_phone2")+"-"+sms_data.get("p_phone3");
								msg.append("[취소완료]");

								msg.append(reservation_dt);
								if(dayCnt>1){
									msg.append("외 ");
									msg.append((dayCnt-1));
									msg.append("일");
								}
								msg.append("/");
								msg.append(room_nm);
								if(into.split(";").length>1){
									msg.append("외 ");
									msg.append((into.split(";").length-1));
									msg.append("객실");
								}
								msg.append(dayCnt);
								msg.append("/");
								msg.append(sms_data.get("reservation_nm"));
								
								String returnCode = smsUtil.send(send, recive, JspUtil.getByteSizeToString(msg.toString(),80));
								//sms 히스토리에 넣기
								vo.setP_nm((String) sms_data.get("p_nm") );
								vo.setFrom_no(send);
								vo.setTo_no(recive);
								vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),80));
								vo.setC_code(returnCode);
								vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
								
								service.pere710Q(vo);
								if("1".equals(returnCode)){
									//sms 카운트 줄이기
									service.pere711Q(vo);
								}
							}
						}
					}
					
				}
			}
		}
		
		
		return mav;
	}	
	
	/**
	 * 종합취소 현황 상세조회
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere707Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();


		List rList = service.pere707_1Q(vo);
		mav.addObject("list", rList);
		mav.addObject("rtAddSvcList", service.pere707_2Q(vo));
		
		//예약자 정보
		mav.addObject("reservationInfo", service.pere705_2Q(vo));
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
		
		SimpleDateFormat frmDatedd = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();//오늘       	
		int nowDt = Integer.parseInt( frmDatedd.format(d1.getTime().getTime()));
		boolean recovery=false;
//		예약복구 처리 쿼리
		if(rList !=null && 0<rList.size()){
			for(int i =0 ; i <rList.size() ;i++){
				Map dt = (Map) rList.get(i);
				int chkDate = Integer.parseInt( (String)dt.get("reservation_dt"));
				if(nowDt<=  chkDate){
					recovery=true;
				}else{
					recovery = false;
					break;
				}
			}
			//예약이 되어있는지 확인
			if(recovery){
				vo.setNext_dates(rList);
				int cnt =service.pere707Q(vo);
				if(cnt>0){
					recovery=false;
				}
			}
			
			if(recovery){
				mav.addObject("recoveryYN","Y");
			}
		}
		
		return mav;
	}
	
	/**
	 * 예약종료 현황 상세조회
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere708Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();

		vo.setRm_status("C");
		
		mav.addObject("list", service.pere705Q(vo));
		mav.addObject("rtAddSvcList", service.pere705_1Q(vo));
		
		//예약자 정보
		mav.addObject("reservationInfo", service.pere705_2Q(vo));
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
		
		COMAVo codeVo = new COMAVo();
		//입금반환 은행
		codeVo.setCode_p_no("04");
		mav.addObject("codeList04",comaService.coma104Q(codeVo));

		
		return mav;
	}
	
	/**
	 * 예약통계
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere800Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();
		SimpleDateFormat frmDateNow = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyy");
		SimpleDateFormat frmDate1 = new SimpleDateFormat("MM");
		SimpleDateFormat frmDateYYYYMMDD = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();//오늘       
		Calendar d2 = Calendar.getInstance();//오늘
		
		String selDt=vo.getReservation_dt();
		if(selDt.length()==6){
			mav.addObject("selDt",selDt+"01");
		}else if(selDt.length()==4){
			mav.addObject("selDt",selDt+frmDate1.format(d1.getTime())+"01");
		}else{
			mav.addObject("selDt",selDt);
		}

		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			vo.setReservation_dt(frmDateNow.format(d1.getTime())+"%");
		}

		
		if("1".equals(vo.getSrc_type())){
			//몇주검색할껀지 조건
			//주간통계
			
			
			SimpleDateFormat frmW = new SimpleDateFormat("W");
			
			//조회 날짜구하기
			Calendar dt_cal = Calendar.getInstance();//오늘      
			int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0,4));
			int mm = Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
			int dd = 1;
			
			dt_cal.set(yyyy, mm,dd);
			
			int lastDay=dt_cal.getActualMaximum(Calendar.DAY_OF_MONTH);
			List nList = new ArrayList();
			
			for(int i=1; i<= lastDay;i++){
				dt_cal.set(yyyy,mm,i);//지정일.
				if(frmW.format(dt_cal.getTime()).equals(vo.getSrc_week()) ){
					nList.add(frmDateYYYYMMDD.format(dt_cal.getTime()) );
				}
			}
			String dates = ((String)nList.get(0)).substring(0,4)+"-"+((String)nList.get(0)).substring(4,6)+"-"+((String)nList.get(0)).substring(6,8);
			dates +=" ~ "+ ((String)nList.get(nList.size()-1)).substring(0,4)+"-"+((String)nList.get(nList.size()-1)).substring(4,6)+"-"+((String)nList.get(nList.size()-1)).substring(6,8);
			
			vo.setNext_dates(nList);
			mav.addObject("list", service.pere800_1Q(vo));
			mav.addObject("title", vo.getReservation_dt().substring(0,4)+"년 "+vo.getReservation_dt().substring(4,6)+"월 "+vo.getSrc_week()+"주 : "+dates);
		}else if("2".equals(vo.getSrc_type())){
			//월간통계
			
			//조회 날짜구하기
			Calendar dt_cal = Calendar.getInstance();//오늘      
			int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0,4));
			int mm = Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
			int dd = 1;
			
			dt_cal.set(yyyy, mm,dd);
			
			int lastDay=dt_cal.getActualMaximum(Calendar.DAY_OF_MONTH);
			List nList = new ArrayList();
			
			for(int i=1; i<= lastDay;i++){
				dt_cal.set(yyyy,mm,i);//지정일.
				nList.add(frmDateYYYYMMDD.format(dt_cal.getTime()) );
			}
			vo.setNext_dates(nList);
			vo.setReservation_dt(vo.getReservation_dt()+"%");
			mav.addObject("map", service.pere800_2Q(vo));
			mav.addObject("list", service.pere800_3Q(vo));
			mav.addObject("title", vo.getReservation_dt().substring(0,4)+"년 "+vo.getReservation_dt().substring(4,6)+"월 ");
		}else if("3".equals(vo.getSrc_type())){
			List nList = new ArrayList();
			
			for(int i=1; i<= 12;i++){
				String m=Integer.toString(i);
				if(i<10){
					m="0"+m;
				}
				
				nList.add(vo.getReservation_dt()+m+"%");
			}
			vo.setNext_dates(nList);
			vo.setReservation_dt(vo.getReservation_dt()+"%");
			mav.addObject("list1", service.pere800_4Q(vo));
			
			
			mav.addObject("list2", service.pere800_5Q(vo));
		}
		
	
		
		mav.addObject("startYYYY", 2012);
		mav.addObject("curYYYY", frmDate.format(d1.getTime()));
		mav.addObject("curMM", frmDate1.format(d1.getTime()));
		
		d2.add(Calendar.YEAR,1);
		mav.addObject("endYYYY", frmDate.format(d2.getTime()));
		
		//객실정보
		mav.addObject("rooms", service.pere101Q(vo) );
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);

		return mav;
	}
	
	/**
	 * 팝업로그인
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere900Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView();
		
		return mav;
	}
	
	/**
	 * 펜션주 로그인 세션 등록
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere901Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView("/common/close");
		
		Map usrInfo = service.pere901Q(vo);
		
		if(null ==usrInfo){
			//로그인 자료가 없을때
//			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("redirect","./pere900Q.do?p_id="+vo.getChk_p_id());
			mav.addObject("msg","아이디 또는 비밀번호가 틀립니다.");

		}else{
			//로그인 성공시
			req.getSession().setAttribute("userInfo", usrInfo);
			
			mav.addObject("parentRedirect","./pere1200Q.do?p_id="+vo.getChk_p_id());
			mav.addObject("closeYN","Y");
		}
		
		return mav;
	}
	
	/**
	 * 로그아웃
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere902Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView("/common/close");

//		req.getSession().invalidate();
		req.getSession().removeAttribute("userInfo");
		req.getSession().removeAttribute("smsChk");
		
		
		mav.addObject("redirect","./pere100Q.do?p_id="+vo.getP_id());
		
		
		return mav;
	}
	
	/**
	 * 관리자 예약
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1000Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("serviceList", service.pere200Q(vo));

		COMAVo codeVo = new COMAVo();
		//전화번호
		codeVo.setCode_p_no("02");
		mav.addObject("code1List",comaService.coma104Q(codeVo));
		//이메일
		codeVo.setCode_p_no("03");
		mav.addObject("code2List",comaService.coma104Q(codeVo));
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);
		

		List aList = petiService.peti300_1Q(petiVo);
		
		List aList1=new ArrayList();
		List aList2=new ArrayList();
		List aList3=new ArrayList();
		List aList4=new ArrayList();
		
		if(aList!=null && 0<aList.size()){
			for( int i=0; i< aList.size();i++){
				Map map = (Map) aList.get(i);
				if("1".equals(map.get("paa_type"))){
					//계좌
					aList1.add(map);
				}else if("2".equals(map.get("paa_type"))){
					//픽업장소
					aList2.add(map);
				}else if("3".equals(map.get("paa_type"))){
					//픽업정보
					aList3.add(map);
				}else if("4".equals(map.get("paa_type"))){
					//도착시간
					aList4.add(map);
				}
			}
		}
		mav.addObject("aList1", aList1);
		mav.addObject("aList2", aList2);
		mav.addObject("aList3", aList3);
		mav.addObject("aList4", aList4);
		
		return mav;
	}
	
	/**
	 * 관리자예약하기
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1001T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		vo.setAdd_type("A");
		isMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		String reservation_dt = vo.getReservation_dt();
		String p_id = vo.getP_id();
		

		//가끔 상태값없이 들어오는 데이터 있음. 관리자에서 들어온듯
		if(null==vo.getRm_status() || "".equals(vo.getRm_status())){
			mav.setViewName("/common/close");
			mav.addObject("redirect","./pere1000Q.do?p_id="+vo.getP_id()+"&reservation_dt="+reservation_dt);
			mav.addObject("msg","잘못된 정보입니다. 다시 확인하세요");
		}
		
		//sms 방명, 숙박일, 등록일
		String smsRoom_nm = "";
		String smsReservation_dt = "";
		String smsReg_dt = "";
		
		int yyyy = Integer.parseInt(reservation_dt.substring(0,4));
		int mm = Integer.parseInt(reservation_dt.substring(4,6))-1;
		int dd = Integer.parseInt(reservation_dt.substring(6,8));
		
		int totalPay = 0;
		
		int totalPayD1 = 0;
		int totalPayD2 = 0;
		int addPay = 0;
		//시작일시 저장 sms
		String startDate="";
		String startRooms="";
		//sms 보낼때 몇박인지
		int bak=0;
		List returnList = new ArrayList();
		
		vo.setP_id(p_id);
		
		//펜션 요금 조회
		for(int i=0;i< vo.getPr_no_cnts().length;i++){
			
			int pr_no = (int) vo.getPr_nos()[vo.getPr_no_cnts()[i]];
			int man_cnt = (int) vo.getMan_cnts()[vo.getPr_no_cnts()[i]];
			int chi_cnt = (int) vo.getChi_cnts()[vo.getPr_no_cnts()[i]];
			int rsv_days = (int) vo.getRsv_days()[vo.getPr_no_cnts()[i]];
			
			vo.setPr_no(pr_no);
			Map payInfo = service.pere202_1Q(vo);
			
			List nextDates = new ArrayList();
			
			//연속된 방의 가격 다시 구하기
			for(int j=0; j<rsv_days;j++){
				bak++;
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d1 = Calendar.getInstance();//오늘       
				
				d1.set(yyyy,mm,dd);//지정일.
				d1.add(Calendar.DATE,j);
//				    //요일 출력.

				SimpleDateFormat weekday222 = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",java.util.Locale.KOREAN);
				SimpleDateFormat weekday = new SimpleDateFormat("EEE",java.util.Locale.KOREAN);

				nextDates.add(frmDate.format(d1.getTime()));
			}
			vo.setNext_dates(nextDates);
			List pList =  service.pere202_2Q(vo);
			
			
			
			for(int j=0; j<pList.size();j++){
				Map map = (Map) pList.get(j);
				String pm_dt = (String) map.get("pm_dt");
				
				//해당 날짜
				String aa = (String) map.get("aa");
				Map returnMap = new HashMap();
				returnMap.put("reservation_dt", aa);
				if(i==0){
					startDate=aa.substring(0,4)+"-"+aa.substring(4,6)+"-"+aa.substring(6,8);
					startRooms=(String) payInfo.get("room_nm");
				}
				
				//sms 관련 정보
				if(i==0 && j==0){
					SimpleDateFormat weekday222 = new SimpleDateFormat("yyyy-MM-dd");
					smsRoom_nm = startRooms;
					smsReservation_dt = startDate;
					Calendar d11 = Calendar.getInstance();//오늘      
					smsReg_dt = weekday222.format(d11.getTime());
					if(vo.getPr_no_cnts().length>1){
						smsRoom_nm = startRooms;
						smsReservation_dt = startDate;
					}else if(rsv_days>1){
						smsReservation_dt = startDate;
					}
				}
				
				returnMap.put("pr_no", pr_no);
				returnMap.put("rowspan", pList.size());
				returnMap.put("man_cnt", man_cnt);
				returnMap.put("chi_cnt", chi_cnt);
				returnMap.put("room_nm", payInfo.get("room_nm"));
				int add_usr_pay = (Integer) payInfo.get("add_usr_pay");
				returnMap.put("add_usr_pay", add_usr_pay);
				

				int totalMan = man_cnt+chi_cnt;
				returnMap.put("totalMan", totalMan);
				returnMap.put("use_man_cnt", payInfo.get("use_man_cnt"));
				//인원수에 따른 가격 설정
				int use_man_cnt = (Integer) payInfo.get("use_man_cnt");
				int pay_man = totalMan-use_man_cnt;
				if(pay_man<0){
					pay_man=0;
				}
				returnMap.put("pay_man", pay_man);
				int pay_man_m = pay_man*(add_usr_pay*1000);
				returnMap.put("pay_man_m", pay_man_m);
				addPay+=pay_man_m;
				totalPay+=pay_man_m;
				//인원수에 따른 가격 설정 끝
				
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d11 = Calendar.getInstance();//오늘       
				

				returnMap.put("nowdt", frmDate.format(d11.getTime()));
				
				if(null!=pm_dt && !"".equals(pm_dt)){
					//설정된 값이 있을때
					int pm_pay=Integer.parseInt( String.valueOf( map.get("o_pm_pay")));
					returnMap.put("pay", pm_pay);
					int pm_per = Integer.parseInt( String.valueOf( map.get("pm_per")));
					int pm_dc_m = Integer.parseInt( String.valueOf( map.get("pm_dc_m")));
					
					if(pm_per!=0 || pm_dc_m!=0 ){
						int dc_pay=Integer.parseInt( String.valueOf( map.get("o_pm_pay")))-Integer.parseInt( String.valueOf( map.get("pm_pay")));
						returnMap.put("dc_pay", dc_pay);
						totalPay-=dc_pay;
						totalPayD1-=dc_pay;
					}else{
						returnMap.put("dc_pay", 0);
					}
					
					totalPay+=pm_pay;
					totalPayD1+=pm_pay;
				}else{
					//설정된 값이 없을때 기본값

					int yyyy1 = Integer.parseInt(aa.substring(0,4));
					int mm1 = Integer.parseInt(aa.substring(4,6))-1;
					int dd1 = Integer.parseInt(aa.substring(6,8));
					
					Calendar d1 = Calendar.getInstance();//오늘       

					d1.set(yyyy1,mm1,dd1);//지정일.
//					    //요일 출력.
					SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",java.util.Locale.KOREAN);
					String dayOfTheWeek = weekday2.format(d1.getTime());

					int pm_pay=0;
					if("일".equals(dayOfTheWeek)
							||"월".equals(dayOfTheWeek)
							||"화".equals(dayOfTheWeek)
							||"수".equals(dayOfTheWeek)
							||"목".equals(dayOfTheWeek)
							){
						pm_pay = (Integer)payInfo.get("busy_1_base")*1000;
					}else if("금".equals(dayOfTheWeek)){
						pm_pay = (Integer)payInfo.get("busy_1_fri")*1000;
					}else if("토".equals(dayOfTheWeek)){
						pm_pay = (Integer)payInfo.get("busy_1_sat")*1000;
					}
					returnMap.put("dc_pay", 0);
					returnMap.put("pay", pm_pay);
					
					totalPay+=pm_pay;
					totalPayD1+=pm_pay;
				}
				
				
				returnList.add(returnMap);
			}
		}
		
		//객식 총 가격
//		totalPayD1 = totalPay;
		
		List rtAddSvcList= new ArrayList();
		//부가서비스 가격 조회
		if(vo.getAs_no_idxs()!=null && vo.getAs_no_idxs().length>0){
			List addServiceList = service.pere200Q(vo);
			for(int i=0;i< vo.getAs_no_idxs().length;i++){
				int as_no = (int) vo.getAs_nos()[vo.getAs_no_idxs()[i]];
				int use_cnt = (int) vo.getUse_cnts()[vo.getAs_no_idxs()[i]];
				String req_msg = vo.getReq_msgs()[vo.getAs_no_idxs()[i]];
				
				for(int jj=0; jj<addServiceList.size();jj++){
					Map map = (Map) addServiceList.get(jj);
					int mAs_no = (Integer) map.get("as_no");
					if(mAs_no==as_no){
						int as_pay =  (Integer) map.get("as_pay");
						
						map.put("as_no", mAs_no);
						map.put("use_cnt", use_cnt);
						map.put("totalPay", (use_cnt*as_pay));
						map.put("reg_msg", req_msg);
						rtAddSvcList.add(map);
						totalPayD2 +=use_cnt*as_pay;
						break;
					}
				}
			}
		}
		totalPay+=totalPayD2;
		
		Map pensionInfo = service.pere203Q(vo);
		
		Calendar chkDt = Calendar.getInstance();//오늘       
		
		int tm = (Integer) pensionInfo.get("wait_time");
		chkDt.add(Calendar.HOUR,tm);
		
		SimpleDateFormat frmChkDt = new SimpleDateFormat("yyyyMMddHHmmss");

		
		vo.setRm_wait_time(frmChkDt.format(chkDt.getTime()));

		Map data = new HashMap();
		data.put("paramMap",vo);
		data.put("list",returnList);
		//부가서비스 리턴
		data.put("rtAddSvcList",rtAddSvcList);

		
		//예약한 객실 수 
		data.put("smsRoomCnt",vo.getPr_no_cnts().length);
		//총 가격
		data.put("totalPay",totalPay);
//		객실명
		data.put("smsRoom_nm",smsRoom_nm);
//		예약일
		data.put("smsReservation_dt",smsReservation_dt);
//		등록일
		data.put("smsReg_dt",smsReg_dt);
//		숙박일
		data.put("smsBak",bak);
		//데이터 저장
		service.pere204T(data);
		
		
//		int totalPay = vo.get("totalPay")==null?1:(Integer)vo.get("totalPay");
//		String smsRoom_nm = (String) vo.get("smsRoom_nm");
//		String smsReservation_dt = (String) vo.get("smsReservation_dt");
//		int smsBak = vo.get("smsBak")==null?1:(Integer)vo.get("smsBak");
		//sms 보내기
		Map smsMap = service.pere1100Q(vo);
		SMSUtil smsUtil = new SMSUtil();
		
		
		mav.setViewName("/common/close");
		mav.addObject("redirect","./pere1000Q.do?p_id="+vo.getP_id()+"&reservation_dt="+reservation_dt);
		mav.addObject("msg","예약되었습니다");

		return mav;
	}
	
	/**
	 * sms 휴대폰 관리
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1100Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("map", service.pere1100Q(vo));
//		mav.addObject("list", service.pere1100_2Q(vo));
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		mav.addObject("list", petiService.peti600Q(petiVo));
		mav.addObject("mapA", petiService.peti301Q(petiVo));
		
		Map pensionInfo = petiService.peti300Q(petiVo);
		
		mav.addObject("pensionInfo",pensionInfo);

		return mav;
	}
	
	/**
	 * sms 환경 변경
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1101T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");

		mav.addObject("redirect","./pere1100Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","수정되었습니다");

		service.pere1101T(vo);
		return mav;
	}
	
	
	public static void main(String[] args) throws UnsupportedEncodingException {
		// TODO Auto-generated method stub
		Calendar today = Calendar.getInstance();
		  System.out.println("이 해의 년도 : " + today.get(Calendar.YEAR));
		  System.out.println("월 (0~11, 0:1월)" +today.get(Calendar.MONTH));
		  System.out.println("이 해의 몇 째 주 : " +today.get(Calendar.WEEK_OF_YEAR));
		  System.out.println("이 달의 몇 째 주 : " +today.get(Calendar.WEEK_OF_MONTH));
		  
		  // DATE와 DAY_OF MONTH는 같다.
		  
		  System.out.println("이 달의 몇 일 : " +today.get(Calendar.DATE));
		  System.out.println("이 달의 몇 일 : " +today.get(Calendar.DAY_OF_MONTH));
		  System.out.println("이 해의 몇 일: " + today.get(Calendar.DAY_OF_YEAR));
		  System.out.println("요일(1~7, 1 : 일요일) : " + today.get(Calendar.DAY_OF_WEEK)); // 1:일요일, 2... 7:토요일
		  System.out.println("이 달의 몇 째 요일 : " + today.get(Calendar.DAY_OF_WEEK_IN_MONTH));
		  System.out.println("오전_오후(0:오전, 1:오후) : " + today.get(Calendar.AM_PM));
		  System.out.println("시간(0~11) : " + today.get(Calendar.HOUR));
		  System.out.println("시간(0~23 : " + today.get(Calendar.HOUR_OF_DAY));
		  System.out.println("분(0~59) : " + today.get(Calendar.MINUTE));
		  System.out.println("초(0~59) : " + today.get(Calendar.SECOND));
		  System.out.println("1000분의 1초 (0~999) : " + today.get(Calendar.MILLISECOND));

	}
	
	/**
	 * 관리자 예약현황
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1200Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {

		isMember(req,res);
		ModelAndView mav = new ModelAndView();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmDate1 = new SimpleDateFormat("yyyyMM");
		
		Calendar d1 = Calendar.getInstance();
		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int chkMonth = Integer.parseInt( frmDate1.format(d1.getTime().getTime()));
		int chkConditionMonth = Integer.parseInt( vo.getReservation_dt().substring(0,6));
		
		//이전달 조회 금지
//		if(chkMonth>chkConditionMonth){
//			vo.setReservation_dt(frmDate.format(d1.getTime()));
//			chkConditionMonth = chkMonth;
//			mav.addObject("msg", "이전달은 예약이 불가능합니다.");
//		}

		Map pensionInfo = petiService.peti300Q(petiVo);
		String p_ico_yn = (String) pensionInfo.get("p_ico_yn");
		String p_id = (String) pensionInfo.get("p_id");
		String friday_yn = (String) pensionInfo.get("friday_yn");
		
		
		//설정한 달 이상 조회금지
		int reservation_use_month = (Integer) pensionInfo.get("reservation_use_month");
		if(reservation_use_month==0){
			reservation_use_month=13;	//예약 최대기간 1년1개월
		}
		reservation_use_month=reservation_use_month-1;
		Calendar maxMonthChk = Calendar.getInstance();
		maxMonthChk.add(Calendar.MONTH, reservation_use_month);
//		int maxMonthNum = Integer.parseInt( frmDate1.format(maxMonthChk.getTime().getTime()));
//		if(chkConditionMonth > maxMonthNum){
//			vo.setReservation_dt(maxMonthNum+"01");
//			chkConditionMonth = maxMonthNum;
//			mav.addObject("msg", (reservation_use_month+1)+"개월 이상은 예약이 불가능합니다.");
//
//		}
		
		mav.addObject("reservation_dt", vo.getReservation_dt());
		
		SimpleDateFormat frmDateDD = new SimpleDateFormat("d");
		
		
		//객실 정보
		List list = service.pere101Q(vo);

		//요금 정보 및 예약정보
		ModelAndView retMv1 =  pere200_3Q(vo,req,res);
		List list2 = (List) ((Map) retMv1.getModel().get("map")).get("list");

		StringBuffer textCal = new StringBuffer();
		
		
		//달력 설정하는 부분
		Calendar drawCal = Calendar.getInstance();
		int sMonthWeek=0;
		int addDate=0;

		//일반달력일때
		int year = Integer.parseInt(vo.getReservation_dt().substring(0,4));
		int month=Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
		int date=1;

		
		Calendar cal = Calendar.getInstance();
		cal.set(year, month, date);
		//지금 요일
		int day1_7 = cal.get(Calendar.DAY_OF_WEEK);
		
		//지금 몇번째 주
		int nowWeek =cal.get(Calendar.DAY_OF_MONTH);
		
		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
		
		
		//이번달 몇번째주
		sMonthWeek =cal.get(Calendar.WEEK_OF_MONTH); 
		
		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
		
		cal.get(Calendar.WEEK_OF_YEAR);

		
		int LastDate = cal.getActualMaximum(Calendar.DATE);

		addDate = (day1_7+6)-7;
		
		
		drawCal.set(year, month, date);
		drawCal.add(Calendar.DATE, -addDate);
		textCal.append("<tr class=\"tt\" align=\"center\">");
		for(int i=0;i<addDate ;i ++){
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			textCal.append("<td class=\"day2\" bgColor=\"#f8f6f7\" vAlign=\"top\" width=\"14%\">&nbsp;&nbsp;&nbsp;</td>");
			drawCal.add(Calendar.DATE, 1);
		}
		
		int chkWeek = 1;
		StringBuffer roomsList = new StringBuffer();
		StringBuffer tdHtml = new StringBuffer();
		int readFast = 0;
		for(int i=1;i<200 ;i ++){
			//초기화
			tdHtml.setLength(0);
			int startDate = addDate+i;
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			if(0!=i && "1".equals(dd)){
				dd=Integer.toString( Integer.parseInt(yyymmdd.substring(4,6))) +"."+dd;
			}
			String gl_busy_type="";
			String gl_pm_dc="";
			String gl_pm_dc_style="";
			
			String nowBgColor="@bgcolor";
			if(Integer.parseInt(frmDate.format(d1.getTime().getTime()))- Integer.parseInt(frmDate.format(drawCal.getTime().getTime()))==0){
				nowBgColor="#e3fefe";
			}
			
			tdHtml.append("<td class=\"day23\" width=\"14%\" valign=\"top\" bgcolor=\""+nowBgColor+"\"");
			tdHtml.append("	id=\"day_"+yyymmdd+"\">");
			tdHtml.append("	<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">");
			tdHtml.append("		<tbody>");
			tdHtml.append("			<tr>");
			tdHtml.append("				<td align=\"left\" valign=\"top\" height=\"100\"><b><a href=\"#\">");
			tdHtml.append("					<font color=\"green\">"+dd+"</font></a></b>");
			tdHtml.append("					<span class=\"pm_nm pms\">@pm_nm&nbsp;</span>");
			tdHtml.append("					<span class=\"pm_dc pms\" style=\"color: red; text-align: center; position: relative; float: left; width: 100%; clear: both;@pm_dc_style\">@pm_dc1&nbsp;</span>");
			
			int reservation_cnt =0; //예약수
			String for_busy_type = "";
			for(int j =0; j< list.size();j++){
				
				Map room = (Map) list.get(j);
				int pr_no = (Integer) room.get("pr_no");
				String room_nm = (String) room.get("room_nm");
				String room_type = (String) room.get("room_type");
				String room_form = (String) room.get("room_form");
				
				int busy_1_base  =   (Integer) room.get("busy_1_base");
				int busy_1_fri   =   (Integer) room.get("busy_1_fri");
				int busy_1_sat	=	(Integer) room.get("busy_1_sat");	
				
				roomsList.setLength(0);
				
				for(int k=readFast; k < list2.size();k++){
//						k=readFast;
					Map dateList = (Map) list2.get(k);
					
					String reservation_dt =  dateList.get("reservation_dt")==null?"":(String)dateList.get("reservation_dt");
					int rd_pr_no = (Integer) dateList.get("pr_no");
					int rm_no= (Integer) dateList.get("rm_no")==null?0:(Integer) dateList.get("rm_no");
					
					if(Integer.parseInt(yyymmdd)< Integer.parseInt(reservation_dt)){
						
						readFast=k-list.size();
						if(readFast<0){
							readFast=0;
						}
						break;
					}
					if(reservation_dt.equals(yyymmdd) && pr_no == rd_pr_no){
						String busy_type = (String) dateList.get("busy_type")==null?"":(String)dateList.get("busy_type");
						for_busy_type = busy_type;
						String rm_status = (String) dateList.get("rm_status")==null?"":(String)dateList.get("rm_status");
						String reservation_nm = (String) dateList.get("reservation_nm")==null?"":(String)dateList.get("reservation_nm");
						String r_phone1 = (String) dateList.get("r_phone1")==null?"":(String)dateList.get("r_phone1");
						String r_phone2 = (String) dateList.get("r_phone2")==null?"":(String)dateList.get("r_phone2");
						String r_phone3 = (String) dateList.get("r_phone3")==null?"":(String)dateList.get("r_phone3");
						int pm_dc_m =  dateList.get("pm_dc_m")==null?0:(Integer)dateList.get("pm_dc_m");
						int pm_per =  dateList.get("pm_per")==null?0:(Integer)dateList.get("pm_per");
						
						String pm_pay = dateList.get("pm_pay")==null?"":String.valueOf(dateList.get("pm_pay")) ;
						gl_pm_dc_style="margin-top:-10px;";
						if("".equals(gl_pm_dc) ){
//							if("Y".equals(pensionInfo.get("pm_dc_yn")) ){
//								if("Y".equals(pensionInfo.get("pm_nm_yn")) ){
//									gl_pm_dc+="<br/>";
//								}
//							}
							gl_pm_dc+="<br/>";
							if(!"".equals(pm_pay) && "Y".equals(pensionInfo.get("pm_dc_yn"))){
								if(pm_dc_m>0){
									gl_pm_dc+="("+"DC : "+pm_dc_m+"원할인)";
								}
								if(pm_per>0){
									gl_pm_dc+="("+"DC : "+pm_per+"% 할인)";
								}
							}	
						}
						
						if("0101".equals(busy_type)){
							gl_busy_type="비수기 주중";
						}else if("0102".equals(busy_type)){
							gl_busy_type="비수기 금요일";
						}else if("0103".equals(busy_type)){
							gl_busy_type="비수기 토요일";
						}else if("0104".equals(busy_type)){
							gl_busy_type="준수기 주중";
						}else if("0105".equals(busy_type)){
							gl_busy_type="준수기 금요일";
						}else if("0106".equals(busy_type)){
							gl_busy_type="준수기 토요일";
						}else if("0107".equals(busy_type)){
							gl_busy_type="성수기 주중";
						}else if("0108".equals(busy_type)){
							gl_busy_type="성수기 금요일";
						}else if("0109".equals(busy_type)){
							gl_busy_type="성수기 토요일";
						}else if("0110".equals(busy_type)){
							gl_busy_type="휴일";
						}else{
							
							if(7==drawCal.get(Calendar.DAY_OF_WEEK)){//토요일
								gl_busy_type="비수기 토요일";
								busy_type = "0103";
							}else	if(6==drawCal.get(Calendar.DAY_OF_WEEK)
									&& "Y".equals(friday_yn)		//금요일 사용 함일경우
									){//금요일
								gl_busy_type="비수기 금요일";
								busy_type = "0102";
							}else{//평일
								gl_busy_type="비수기 주중";
								busy_type = "0101";
							}	
						}
						if("N".equals(pensionInfo.get("pm_nm_yn")) ){
							gl_busy_type="";
						}
						if("0110".equals(busy_type)){
							roomsList.append(" ");
							//휴일일때 객실 초기화
						}else{
							roomsList.append("					<span	class=\"divDel\"><br/>");
							if("Y".equals(p_ico_yn)){
								if("F".equals(room_type)){
									roomsList.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");	
								}else if("C".equals(room_type)){
									roomsList.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								}else if("B".equals(room_type)){
									roomsList.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								}
							}
							String viewNm = room_nm;
							if("C".equals(rm_status)){
								viewNm="<span class=\"ptrend\">완료["+reservation_nm+"]</span>";
								reservation_cnt++;
							}else if("R".equals(rm_status)){
								viewNm="<span class=\"ptrstandby\">대기["+reservation_nm+"]</span>";
								reservation_cnt++;
							}
							String r_phone="";
							if(null != r_phone1 && !"".equals(r_phone1)){
								r_phone=r_phone1+"-"+r_phone2+"-"+r_phone3;
							}
							
							roomsList.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
							roomsList.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
							roomsList.append("							onmouseout=\"hideTip()\"> ");
							roomsList.append("							<a href=\"#\" id=\"a_"+pr_no+"_"+yyymmdd+"\"");
							roomsList.append("								onclick=\"goReserrvation('"+p_id+"',this,'"+pr_no+"');\" room_nm=\" "+room_nm+"\"");
							roomsList.append("								room_form=\""+room_form+"\" room_type=\""+room_type+"\" rm_status=\""+rm_status+"\" date=\""+yyymmdd+"\"");
							roomsList.append("								busy_1_base=\""+busy_1_base+"\" busy_1_fri=\""+busy_1_fri+"\" busy_1_sat=\""+busy_1_sat+"\" ");
							if(!"".equals(reservation_nm)){
								roomsList.append("								reservation_nm=\""+reservation_nm+"\" r_phone=\""+r_phone+"\" ");	
							}

							if(!"".equals(pm_pay)){
								roomsList.append("						pm_pay=\""+pm_pay+"\"");	
							}
							if(0!=rm_no){
								roomsList.append("						rm_no=\""+rm_no+"\"");
							}
							
							roomsList.append("								busy_type=\""+busy_type+"\"> "+viewNm+"</a>");
							roomsList.append("						</span>");
							roomsList.append("					</span>");
						}
						
					}
				}
//					설정 안되어있을경우 기본으로 설정합
				if("".equals(roomsList.toString()) ){
					//요금 설정해야함. 
					String busy_type = "";
					
					if(7==drawCal.get(Calendar.DAY_OF_WEEK)){//토요일
						gl_busy_type="비수기 토요일";
						busy_type = "0103";
					}else	if(6==drawCal.get(Calendar.DAY_OF_WEEK)
							&& "Y".equals(friday_yn)		//금요일 사용 함일경우
							){//금요일
						gl_busy_type="비수기 금요일";
						busy_type = "0102";
					}else{//평일
						gl_busy_type="비수기 주중";
						busy_type = "0101";
					}
					if("N".equals(pensionInfo.get("pm_nm_yn")) ){
						gl_busy_type="";
					}
					
					//기본값 설정
					roomsList.append("					<span	class=\"divDel\"><br/>");
					if("Y".equals(p_ico_yn)){
						if("F".equals(room_type)){
							roomsList.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");	
						}else if("C".equals(room_type)){
							roomsList.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						}else if("B".equals(room_type)){
							roomsList.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						}
					}
					roomsList.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
					roomsList.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
					roomsList.append("							onmouseout=\"hideTip()\"> ");
					roomsList.append("							<a href=\"#\" id=\"a_"+pr_no+"_"+yyymmdd+"\"");
					roomsList.append("								onclick=\"goReserrvation('"+p_id+"',this,'"+pr_no+"');\" room_nm=\" "+room_nm+"\"");
					roomsList.append("								room_form=\""+room_form+"\" room_type=\""+room_type+"\" rm_status=\"\" date=\""+yyymmdd+"\"");
					roomsList.append("								busy_1_base=\""+busy_1_base+"\" busy_1_fri=\""+busy_1_fri+"\" busy_1_sat=\""+busy_1_sat+"\" ");
					roomsList.append("								busy_type=\""+busy_type+"\"> "+room_nm+"</a>");
					roomsList.append("						</span>");
					roomsList.append("					</span>");
				}else{
					
				}
				//휴일일 경우 객실정보 입력안함
				if(!"0110".equals(for_busy_type)){
					tdHtml.append(roomsList.toString());	
				}
			}
			//휴일일경우 이미지로 대체
			if("0110".equals(for_busy_type)){
				tdHtml.append("<br/><table style=\"width:100%;height:100%;text-align: center\"><tr><td valign='middle'><img src=\"/usr/images/reservation.jpg\" border=\"0\" style=\"\"/></td></tr></table>");
			}
			/////


			//색지정
			if(reservation_cnt==0){//예약 없을때
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fefefe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style) );

			}else if(reservation_cnt==list.size()){//예약 모두 찬거
				textCal.append(tdHtml.toString()
						.replace("@bgcolor", "#fafc98")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style) );
			}else{//예약 조금 찬거
				textCal.append(tdHtml.toString()
						.replace("@bgcolor", "#fef0fe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style) );
			}

			textCal.append("				</td>");
			textCal.append("			</tr>");
			textCal.append("		</tbody>");
			textCal.append("	</table>");
			textCal.append("</td>");
			
			if(startDate % 7==0){
				textCal.append("</tr>");
				if(sMonthWeek==chkWeek){
					break;
				}
				textCal.append("<tr class=\"tt\" align=\"center\">");
				chkWeek++;
			}
			drawCal.add(Calendar.DATE, 1);
			
		}
			

		
		mav.addObject("txtCal",textCal.toString());
		
		
		mav.addObject("pensionInfo",pensionInfo);
		
		vo.setSb_type("brd");
		mav.addObject("brdList", service.pere100Q(vo));
		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));
		return mav;
	}
	
	/**
	 * 1200 테스트 완료 되면 삭제
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1300Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmDate1 = new SimpleDateFormat("yyyyMM");
		
		Calendar d1 = Calendar.getInstance();
		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int chkMonth = Integer.parseInt( frmDate1.format(d1.getTime().getTime()));
		int chkConditionMonth = Integer.parseInt( vo.getReservation_dt().substring(0,6));
		
		//이전달 조회 금지
		if(chkMonth>chkConditionMonth){
			vo.setReservation_dt(frmDate.format(d1.getTime()));
			chkConditionMonth = chkMonth;
			mav.addObject("msg", "이전달은 예약이 불가능합니다.");
		}

		Map pensionInfo = petiService.peti300Q(petiVo);
		String p_ico_yn = (String) pensionInfo.get("p_ico_yn");
		String p_id = (String) pensionInfo.get("p_id");
		String friday_yn = (String) pensionInfo.get("friday_yn");
		
		
		//설정한 달 이상 조회금지
		int reservation_use_month = (Integer) pensionInfo.get("reservation_use_month");
		if(reservation_use_month==0){
			reservation_use_month=13;	//예약 최대기간 1년1개월
		}
		reservation_use_month=reservation_use_month-1;
		Calendar maxMonthChk = Calendar.getInstance();
		maxMonthChk.add(Calendar.MONTH, reservation_use_month);
		int maxMonthNum = Integer.parseInt( frmDate1.format(maxMonthChk.getTime().getTime()));
		if(chkConditionMonth > maxMonthNum){
			vo.setReservation_dt(maxMonthNum+"01");
			chkConditionMonth = maxMonthNum;
			mav.addObject("msg", (reservation_use_month+1)+"개월 이상은 예약이 불가능합니다.");

		}
		
		mav.addObject("reservation_dt", vo.getReservation_dt());
		
		SimpleDateFormat frmDateDD = new SimpleDateFormat("d");
		
		
		//객실 정보
		List list = service.pere101Q(vo);

		//요금 정보 및 예약정보
		ModelAndView retMv1 =  pere200_3Q(vo,req,res);
		List list2 = (List) ((Map) retMv1.getModel().get("map")).get("list");

		StringBuffer textCal = new StringBuffer();
		
		
		//달력 설정하는 부분
		Calendar drawCal = Calendar.getInstance();
		int sMonthWeek=0;
		int addDate=0;

		//일반달력일때
		int year = Integer.parseInt(vo.getReservation_dt().substring(0,4));
		int month=Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
		int date=1;

		
		Calendar cal = Calendar.getInstance();
		cal.set(year, month, date);
		//지금 요일
		int day1_7 = cal.get(Calendar.DAY_OF_WEEK);
		
		//지금 몇번째 주
		int nowWeek =cal.get(Calendar.DAY_OF_MONTH);
		
		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
		
		
		//이번달 몇번째주
		sMonthWeek =cal.get(Calendar.WEEK_OF_MONTH); 
		
		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
		
		cal.get(Calendar.WEEK_OF_YEAR);

		
		int LastDate = cal.getActualMaximum(Calendar.DATE);

		addDate = (day1_7+6)-7;
		
		
		drawCal.set(year, month, date);
		drawCal.add(Calendar.DATE, -addDate);
		textCal.append("<tr class=\"tt\" align=\"center\">");
		for(int i=0;i<addDate ;i ++){
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			textCal.append("<td class=\"day2\" bgColor=\"#f8f6f7\" vAlign=\"top\" width=\"14%\">&nbsp;&nbsp;&nbsp;</td>");
			drawCal.add(Calendar.DATE, 1);
		}
		
		int chkWeek = 1;
		StringBuffer roomsList = new StringBuffer();
		StringBuffer tdHtml = new StringBuffer();
		int readFast = 0;
		for(int i=1;i<200 ;i ++){
			//초기화
			tdHtml.setLength(0);
			int startDate = addDate+i;
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			if(0!=i && "1".equals(dd)){
				dd=Integer.toString( Integer.parseInt(yyymmdd.substring(4,6))) +"."+dd;
			}
			String gl_busy_type="";
			String gl_pm_dc="";
			String gl_pm_dc_style="";
			
			String nowBgColor="@bgcolor";
			if(Integer.parseInt(frmDate.format(d1.getTime().getTime()))- Integer.parseInt(frmDate.format(drawCal.getTime().getTime()))==0){
				nowBgColor="#e3fefe";
			}
			
			tdHtml.append("<td class=\"day23\" width=\"14%\" valign=\"top\" bgcolor=\""+nowBgColor+"\"");
			tdHtml.append("	id=\"day_"+yyymmdd+"\">");
			tdHtml.append("	<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">");
			tdHtml.append("		<tbody>");
			tdHtml.append("			<tr>");
			tdHtml.append("				<td align=\"left\" valign=\"top\" height=\"100\"><b><a href=\"#\">");
			tdHtml.append("					<font color=\"green\">"+dd+"</font></a></b>");
			tdHtml.append("					<span class=\"pm_nm pms\">@pm_nm&nbsp;</span>");
			tdHtml.append("					<span class=\"pm_dc pms\" style=\"color: red; text-align: center; position: relative; float: left; width: 100%; clear: both;@pm_dc_style\">@pm_dc1&nbsp;</span>");
			
			int reservation_cnt =0; //예약수
			for(int j =0; j< list.size();j++){
				
				Map room = (Map) list.get(j);
				int pr_no = (Integer) room.get("pr_no");
				String room_nm = (String) room.get("room_nm");
				String room_type = (String) room.get("room_type");
				String room_form = (String) room.get("room_form");
				
				int busy_1_base  =   (Integer) room.get("busy_1_base");
				int busy_1_fri   =   (Integer) room.get("busy_1_fri");
				int busy_1_sat	=	(Integer) room.get("busy_1_sat");	
				
				roomsList.setLength(0);
				
				for(int k=readFast; k < list2.size();k++){
//						k=readFast;
					Map dateList = (Map) list2.get(k);
					
					String reservation_dt =  dateList.get("reservation_dt")==null?"":(String)dateList.get("reservation_dt");
					int rd_pr_no = (Integer) dateList.get("pr_no");
					int rm_no= (Integer) dateList.get("rm_no")==null?0:(Integer) dateList.get("rm_no");
					
					if(Integer.parseInt(yyymmdd)< Integer.parseInt(reservation_dt)){
						
						readFast=k-list.size();
						if(readFast<0){
							readFast=0;
						}
						break;
					}
					if(reservation_dt.equals(yyymmdd) && pr_no == rd_pr_no){
						String busy_type = (String) dateList.get("busy_type")==null?"":(String)dateList.get("busy_type");
						String rm_status = (String) dateList.get("rm_status")==null?"":(String)dateList.get("rm_status");
						String reservation_nm = (String) dateList.get("reservation_nm")==null?"":(String)dateList.get("reservation_nm");
						String r_phone1 = (String) dateList.get("r_phone1")==null?"":(String)dateList.get("r_phone1");
						String r_phone2 = (String) dateList.get("r_phone2")==null?"":(String)dateList.get("r_phone2");
						String r_phone3 = (String) dateList.get("r_phone3")==null?"":(String)dateList.get("r_phone3");
						int pm_dc_m =  dateList.get("pm_dc_m")==null?0:(Integer)dateList.get("pm_dc_m");
						int pm_per =  dateList.get("pm_per")==null?0:(Integer)dateList.get("pm_per");
						
						String pm_pay = dateList.get("pm_pay")==null?"":String.valueOf(dateList.get("pm_pay")) ;
						gl_pm_dc_style="margin-top:-10px;";
						if("".equals(gl_pm_dc) ){
//							if("Y".equals(pensionInfo.get("pm_dc_yn")) ){
//								if("Y".equals(pensionInfo.get("pm_nm_yn")) ){
//									gl_pm_dc+="<br/>";
//								}
//							}
							gl_pm_dc+="<br/>";
							if(!"".equals(pm_pay) && "Y".equals(pensionInfo.get("pm_dc_yn"))){
								if(pm_dc_m>0){
									gl_pm_dc+="("+"DC : "+pm_dc_m+"원할인)";
								}
								if(pm_per>0){
									gl_pm_dc+="("+"DC : "+pm_per+"% 할인)";
								}
							}	
						}
						
						if("0101".equals(busy_type)){
							gl_busy_type="비수기 주중";
						}else if("0102".equals(busy_type)){
							gl_busy_type="비수기 금요일";
						}else if("0103".equals(busy_type)){
							gl_busy_type="비수기 토요일";
						}else if("0104".equals(busy_type)){
							gl_busy_type="준수기 주중";
						}else if("0105".equals(busy_type)){
							gl_busy_type="준수기 금요일";
						}else if("0106".equals(busy_type)){
							gl_busy_type="준수기 토요일";
						}else if("0107".equals(busy_type)){
							gl_busy_type="성수기 주중";
						}else if("0108".equals(busy_type)){
							gl_busy_type="성수기 금요일";
						}else if("0109".equals(busy_type)){
							gl_busy_type="성수기 토요일";
						}else{
							
							if(7==drawCal.get(Calendar.DAY_OF_WEEK)){//토요일
								gl_busy_type="비수기 토요일";
								busy_type = "0103";
							}else	if(6==drawCal.get(Calendar.DAY_OF_WEEK)
									&& "Y".equals(friday_yn)		//금요일 사용 함일경우
									){//금요일
								gl_busy_type="비수기 금요일";
								busy_type = "0102";
							}else{//평일
								gl_busy_type="비수기 주중";
								busy_type = "0101";
							}	
						}
						if("N".equals(pensionInfo.get("pm_nm_yn")) ){
							gl_busy_type="";
						}
						
						roomsList.append("					<span	class=\"divDel\"><br/>");
						if("Y".equals(p_ico_yn)){
							if("F".equals(room_type)){
								roomsList.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");	
							}else if("C".equals(room_type)){
								roomsList.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
							}else if("B".equals(room_type)){
								roomsList.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
							}
						}
						String viewNm = room_nm;
						if("C".equals(rm_status)){
							viewNm="<span class=\"ptrend\">완료["+reservation_nm+"]</span>";
							reservation_cnt++;
						}else if("R".equals(rm_status)){
							viewNm="<span class=\"ptrstandby\">대기["+reservation_nm+"]</span>";
							reservation_cnt++;
						}
						String r_phone="";
						if(null != r_phone1 && !"".equals(r_phone1)){
							r_phone=r_phone1+"-"+r_phone2+"-"+r_phone3;
						}
						
						roomsList.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
						roomsList.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
						roomsList.append("							onmouseout=\"hideTip()\"> ");
						roomsList.append("							<a href=\"#\" id=\"a_"+pr_no+"_"+yyymmdd+"\"");
						roomsList.append("								onclick=\"goReserrvation('"+p_id+"',this,'"+pr_no+"');\" room_nm=\" "+room_nm+"\"");
						roomsList.append("								room_form=\""+room_form+"\" room_type=\""+room_type+"\" rm_status=\""+rm_status+"\" date=\""+yyymmdd+"\"");
						roomsList.append("								busy_1_base=\""+busy_1_base+"\" busy_1_fri=\""+busy_1_fri+"\" busy_1_sat=\""+busy_1_sat+"\" ");
						if(!"".equals(reservation_nm)){
							roomsList.append("								reservation_nm=\""+reservation_nm+"\" r_phone=\""+r_phone+"\" ");	
						}

						if(!"".equals(pm_pay)){
							roomsList.append("						pm_pay=\""+pm_pay+"\"");	
						}
						if(0!=rm_no){
							roomsList.append("						rm_no=\""+rm_no+"\"");
						}
						
						roomsList.append("								busy_type=\""+busy_type+"\"> "+viewNm+"</a>");
						roomsList.append("						</span>");
						roomsList.append("					</span>");
					}
				}
//					설정 안되어있을경우 기본으로 설정합
				if("".equals(roomsList.toString()) ){
					//요금 설정해야함. 
					String busy_type = "";
					
					if(7==drawCal.get(Calendar.DAY_OF_WEEK)){//토요일
						gl_busy_type="비수기 토요일";
						busy_type = "0103";
					}else	if(6==drawCal.get(Calendar.DAY_OF_WEEK)
							&& "Y".equals(friday_yn)		//금요일 사용 함일경우
							){//금요일
						gl_busy_type="비수기 금요일";
						busy_type = "0102";
					}else{//평일
						gl_busy_type="비수기 주중";
						busy_type = "0101";
					}
					if("N".equals(pensionInfo.get("pm_nm_yn")) ){
						gl_busy_type="";
					}
					
					//기본값 설정
					roomsList.append("					<span	class=\"divDel\"><br/>");
					if("Y".equals(p_ico_yn)){
						if("F".equals(room_type)){
							roomsList.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");	
						}else if("C".equals(room_type)){
							roomsList.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						}else if("B".equals(room_type)){
							roomsList.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						}
					}
					roomsList.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
					roomsList.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
					roomsList.append("							onmouseout=\"hideTip()\"> ");
					roomsList.append("							<a href=\"#\" id=\"a_"+pr_no+"_"+yyymmdd+"\"");
					roomsList.append("								onclick=\"goReserrvation('"+p_id+"',this,'"+pr_no+"');\" room_nm=\" "+room_nm+"\"");
					roomsList.append("								room_form=\""+room_form+"\" room_type=\""+room_type+"\" rm_status=\"\" date=\""+yyymmdd+"\"");
					roomsList.append("								busy_1_base=\""+busy_1_base+"\" busy_1_fri=\""+busy_1_fri+"\" busy_1_sat=\""+busy_1_sat+"\" ");
					roomsList.append("								busy_type=\""+busy_type+"\"> "+room_nm+"</a>");
					roomsList.append("						</span>");
					roomsList.append("					</span>");
				}else{
					
				}
				tdHtml.append(roomsList.toString());
			}

			//색지정
			if(reservation_cnt==0){//예약 없을때
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fefefe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style) );

			}else if(reservation_cnt==list.size()){//예약 모두 찬거
				textCal.append(tdHtml.toString()
						.replace("@bgcolor", "#fafc98")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style) );
			}else{//예약 조금 찬거
				textCal.append(tdHtml.toString()
						.replace("@bgcolor", "#fef0fe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style) );
			}

			textCal.append("				</td>");
			textCal.append("			</tr>");
			textCal.append("		</tbody>");
			textCal.append("	</table>");
			textCal.append("</td>");
			
			if(startDate % 7==0){
				textCal.append("</tr>");
				if(sMonthWeek==chkWeek){
					break;
				}
				textCal.append("<tr class=\"tt\" align=\"center\">");
				chkWeek++;
			}
			drawCal.add(Calendar.DATE, 1);
			
		}
			

		
		mav.addObject("txtCal",textCal.toString());
		
		
		mav.addObject("pensionInfo",pensionInfo);
		
		vo.setSb_type("brd");
		mav.addObject("brdList", service.pere100Q(vo));
		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));
		return mav;
	}
	
	/**
	 * 예약 대기 ,예약 완료 복구
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1400T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");


		List rList = service.pere707_1Q(vo);
		mav.addObject("list", rList);
		List svsList =service.pere707_2Q(vo);
		
		Map reservationInfo = service.pere705_2Q(vo);
		//예약자 정보
//		mav.addObject("reservationInfo", reservationInfo);
		
		PEREVo usrInfo = new PEREVo();
		Map data = new HashMap();
		data.put("list", rList);
		data.put("rtAddSvcList", svsList);
		data.put("reservationInfo", reservationInfo);
		
		SMCommonUtil smUtil = new SMCommonUtil();
		smUtil.mapToBean(reservationInfo, vo);
		
		data.put("paramMap", vo);
		
		SimpleDateFormat frmDatedd = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();//오늘       	
		
		int nowDt = Integer.parseInt( frmDatedd.format(d1.getTime().getTime()));
		boolean recovery=false;

//		예약복구 처리 쿼리
		if(rList !=null && 0<rList.size()){
			for(int i =0 ; i <rList.size() ;i++){
				Map dt = (Map) rList.get(i);
				int chkDate = Integer.parseInt( (String)dt.get("reservation_dt"));
				if(nowDt<=  chkDate){
					recovery=true;
				}else{
					recovery = false;
					break;
				}
			}
			//예약이 되어있는지 확인
			if(recovery){
				vo.setNext_dates(rList);
				int cnt =service.pere707Q(vo);
				if(cnt>0){
					recovery=false;
				}
			}
			
			if(recovery){

				service.pere1400T(data);
				
				String reservation_dt = (String)((Map)rList.get(0)).get("reservation_dt");		
				mav.setViewName("/common/close");
				mav.addObject("redirect","./pere1200Q.do?p_id="+vo.getP_id()+"&reservation_dt="+reservation_dt);
				mav.addObject("msg","예약되었습니다");
			}else{
				mav.setViewName("/common/close");
				mav.addObject("redirect","./pere703Q.do?p_id="+vo.getP_id());
				mav.addObject("msg","!!!!!!!!!!!!!예약 실패!!!!!!!!!!!!!!! 해당일에 예약이 되어있습니다");
			}
		}
		
		return mav;
	}
	
	
	/**
	 * 문자보내기
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1500Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		
		ModelAndView mav = new ModelAndView();
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		
		Map pensionInfo = petiService.peti300Q(petiVo);
		mav.addObject("pensionInfo", pensionInfo);
		List list = service.pere1500Q(vo);
		List returnList = new ArrayList();
		if(list !=null && list.size()>0){
			String reservation_dt = "";
			for(int i=0; i < list.size() ; i ++){
				Map map = (Map) list.get(i);
				if(!map.get("reservation_dt").equals(reservation_dt)){
					map.put("col", map.get("row_cnt"));
					reservation_dt = (String) map.get("reservation_dt"); 
				}
				returnList.add(map);
			}
		}
		mav.addObject("smsReservationList", returnList);
		
		
		
		return mav;
	}
	
	/**
	 * sms문자전송 전송내용
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1501Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		
		ModelAndView mav = new ModelAndView();
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		if(null != vo.getSrc_sdate() && !"".equals(vo.getSrc_sdate())){
			vo.setSrc_sdate(vo.getSrc_sdate().replaceAll("-", "")+"%");
		}
		
		Map pensionInfo = petiService.peti300Q(petiVo);
		mav.addObject("pensionInfo", pensionInfo);
//		mav.addObject("smsList", pensionInfo);
		vo.setRecordCountPerPage(10);
		PaginationInfo paginationInfo = new PaginationInfo();
		int currnetPageNo = vo.getCurrentPageNo() <= 1 ? 1 : (Integer) vo
				.getCurrentPageNo();
		vo.setCurrentPageNo(currnetPageNo);
		vo.setParamMap(requestPram2Map(req));


		int iTotalCnt = service.pere1501Q_cnt(vo);
		vo.setTotalRecordCount(iTotalCnt);
		
		if(iTotalCnt>0){
			
			// 상위 코드목록
			mav.addObject("list", service.pere1501Q(vo));
			mav.addObject("pageHtml", vo.getToHtml("./pere1501Q.do"));
			mav.addObject("paginationInfo", vo);
		}
		
		
		List list = service.pere1500Q(vo);
		List returnList = new ArrayList();
		if(list !=null && list.size()>0){
			String reservation_dt = "";
			for(int i=0; i < list.size() ; i ++){
				Map map = (Map) list.get(i);
				if(!map.get("reservation_dt").equals(reservation_dt)){
					map.put("col", map.get("row_cnt"));
					reservation_dt = (String) map.get("reservation_dt"); 
				}
				returnList.add(map);
			}
		}
		mav.addObject("smsReservationList", returnList);
		
		

		
		return mav;
	}
	
	/**
	 * sms 삭제
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1502T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/common/close");
		mav.addObject("redirect","./pere1501Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","삭제했습니다");
		String[] etc_data = vo.getEtc_data().split(";");
		List list = new ArrayList();
		
		for(int i =0 ; i < etc_data.length;i++){
			list.add(etc_data[i]);
		}
		vo.setList(list);
		
		service.pere1502T(vo);
		return mav;
	}
	
	
	/**
	 * 문자 전송 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1600T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		
		ModelAndView mav = new ModelAndView();
		SMSUtil smsUtil = new SMSUtil();

		String send = vo.getSendPhone();
		String msg = vo.getReq_msg();

		StringBuffer ReturnMsg = new StringBuffer();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());

		
		
		for(int i=0;i < vo.getPhones().length;i++){
			String recive = vo.getPhones()[i];
			String returnCode="";
			
			Map pensionInfo = petiService.peti300Q(petiVo);
			if("Y".equals(pensionInfo.get("sms_send_yn"))){
				int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
				
				if(chk_sms_cnt > 0){

					if("1".equals(vo.getSendType())){
//						바로 전송
						returnCode = smsUtil.send(send, recive, JspUtil.getByteSizeToString(msg.toString(),80));

					}else{
//						예약전송
						String res_dt = vo.getRes_dt();
						String res_tm = vo.getRes_tm();
						SimpleDateFormat frmDate1 = new SimpleDateFormat("yyyyMMddHHmmss");
						Calendar d1 = Calendar.getInstance();
						String seq = frmDate1.format(d1.getTime()) + i;
						returnCode = smsUtil.sendSMSReserve(send, recive, JspUtil.getByteSizeToString(msg.toString(),80),res_dt,res_tm,seq);
						
						vo.setSms_reservation_no(seq);
						vo.setReservation_dt(res_dt.replaceAll("-", "")+res_tm.replaceAll(":", ""));
					}

					vo.setFrom_no(send);
					vo.setTo_no(recive);
					vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),80));
					vo.setC_code(returnCode);
					vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
					
					service.pere710Q(vo);
					if("1".equals(returnCode)){
						//sms 카운트 줄이기
						service.pere711Q(vo);
						ReturnMsg.append(recive);
						ReturnMsg.append(" : 전송 성공&nn");
						
					}else{
						ReturnMsg.append(recive);
						ReturnMsg.append(" : 전송 실패(");
						ReturnMsg.append(vo.getC_msg());
						ReturnMsg.append(")&nn");
					}
				}
			}
			
		}
		mav.setViewName("/common/close");
		mav.addObject("redirect","./pere1500Q.do?p_id="+vo.getP_id());
		mav.addObject("msg",ReturnMsg.toString());
		
		return mav;
	}
	
	/**
	 * sms 예약전송 취소
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1601T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		
		ModelAndView mav = new ModelAndView();
		SMSUtil smsUtil = new SMSUtil();

		String send = vo.getSendPhone();
		String msg = vo.getReq_msg();

		StringBuffer ReturnMsg = new StringBuffer();
		
		for(int i=0;i < vo.getSms_reservation_nos().length;i++){

			vo.setSms_reservation_no(vo.getSms_reservation_nos()[i]);
			//예약취소
			int returnInt= smsUtil.cancelSMSReserve(vo.getSms_reservation_nos()[i]);
//				예약전송
			
			
			if(returnInt ==1){
				//sms 카운트 +1
				service.pere710_0Q(vo);
				service.pere712Q(vo);
//				ReturnMsg.append(recive);
//				ReturnMsg.append(" : 전송 성공&nn");
				
			}else{
//				ReturnMsg.append(recive);
//				ReturnMsg.append(" : 전송 실패(");
//				ReturnMsg.append(vo.getC_msg());
//				ReturnMsg.append(")&nn");
			}
		}
		mav.setViewName("/common/close");
		mav.addObject("redirect","./pere1500Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","예약전송 삭제 되었습니다");
		
		return mav;
	}
	
	/**
	 * 게시판별 문자 불러오기
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1700Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		
		
		jsonMap.put("list", service.pere1700Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}
	
	/**
	 * sms 문자 저장하기
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1800T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		service.pere1800T(vo);
		
		jsonMap.put("resultCode", "Y");
		mav.addObject("map", jsonMap);
		return mav;
	}
	
	/**
	 * sms 문자 삭제하기
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1900T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		
		
		jsonMap.put("resultCode", service.pere1900T(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}
	
	/**
	 * 해당 구간 사용자 전화번호 이름 조회
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere2000Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		
		if((null ==vo.getP_id() || "".equals(vo.getP_id())) 
				||
				(null != vo.getReservation_dt() && vo.getReservation_dt().length()>8)
				){
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg","접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn","Y");
			
			return mav;
		}
		
		vo.setSrc_sdt(vo.getSrc_sdt().replaceAll("-", ""));
		vo.setSrc_edt(vo.getSrc_edt().replaceAll("-", ""));
		
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		
		
		jsonMap.put("list", service.pere2000Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}
	
	
	/**
	 * 게시판 조회
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere2100Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("list", service.pere2100Q(vo));
		return mav;
	}
	
	
	/**
	 * 휴대전화로 인증처리 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere2200Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("list", service.pere2200Q(vo));
		return mav;
	}
	
	
	/**
	 * 예약현황조회 팝업
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView perePop1200Q(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {

		isMember(req,res);
		ModelAndView mav = new ModelAndView();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmDate1 = new SimpleDateFormat("yyyyMM");
		
		Calendar d1 = Calendar.getInstance();
		if(null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())){
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int chkMonth = Integer.parseInt( frmDate1.format(d1.getTime().getTime()));
		int chkConditionMonth = Integer.parseInt( vo.getReservation_dt().substring(0,6));
		
		//이전달 조회 금지
//		if(chkMonth>chkConditionMonth){
//			vo.setReservation_dt(frmDate.format(d1.getTime()));
//			chkConditionMonth = chkMonth;
//			mav.addObject("msg", "이전달은 예약이 불가능합니다.");
//		}

		Map pensionInfo = petiService.peti300Q(petiVo);
		String p_ico_yn = (String) pensionInfo.get("p_ico_yn");
		String p_id = (String) pensionInfo.get("p_id");
		String friday_yn = (String) pensionInfo.get("friday_yn");
		
		
		//설정한 달 이상 조회금지
		int reservation_use_month = (Integer) pensionInfo.get("reservation_use_month");
		if(reservation_use_month==0){
			reservation_use_month=13;	//예약 최대기간 1년1개월
		}
		reservation_use_month=reservation_use_month-1;
		Calendar maxMonthChk = Calendar.getInstance();
		maxMonthChk.add(Calendar.MONTH, reservation_use_month);
//		int maxMonthNum = Integer.parseInt( frmDate1.format(maxMonthChk.getTime().getTime()));
//		if(chkConditionMonth > maxMonthNum){
//			vo.setReservation_dt(maxMonthNum+"01");
//			chkConditionMonth = maxMonthNum;
//			mav.addObject("msg", (reservation_use_month+1)+"개월 이상은 예약이 불가능합니다.");
//
//		}
		
		mav.addObject("reservation_dt", vo.getReservation_dt());
		
		SimpleDateFormat frmDateDD = new SimpleDateFormat("d");
		
		
		//객실 정보
		List list = service.pere101Q(vo);

		//요금 정보 및 예약정보
		ModelAndView retMv1 =  pere200_3Q(vo,req,res);
		List list2 = (List) ((Map) retMv1.getModel().get("map")).get("list");

		StringBuffer textCal = new StringBuffer();
		
		
		//달력 설정하는 부분
		Calendar drawCal = Calendar.getInstance();
		int sMonthWeek=0;
		int addDate=0;

		//일반달력일때
		int year = Integer.parseInt(vo.getReservation_dt().substring(0,4));
		int month=Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
		int date=1;

		
		Calendar cal = Calendar.getInstance();
		cal.set(year, month, date);
		//지금 요일
		int day1_7 = cal.get(Calendar.DAY_OF_WEEK);
		
		//지금 몇번째 주
		int nowWeek =cal.get(Calendar.DAY_OF_MONTH);
		
		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
		
		
		//이번달 몇번째주
		sMonthWeek =cal.get(Calendar.WEEK_OF_MONTH); 
		
		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
		
		cal.get(Calendar.WEEK_OF_YEAR);

		
		int LastDate = cal.getActualMaximum(Calendar.DATE);

		addDate = (day1_7+6)-7;
		
		
		drawCal.set(year, month, date);
		drawCal.add(Calendar.DATE, -addDate);
		textCal.append("<tr class=\"tt\" align=\"center\">");
		for(int i=0;i<addDate ;i ++){
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			textCal.append("<td class=\"day2\" bgColor=\"#f8f6f7\" vAlign=\"top\" width=\"14%\">&nbsp;&nbsp;&nbsp;</td>");
			drawCal.add(Calendar.DATE, 1);
		}
		
		int chkWeek = 1;
		StringBuffer roomsList = new StringBuffer();
		StringBuffer tdHtml = new StringBuffer();
		int readFast = 0;
		for(int i=1;i<200 ;i ++){
			//초기화
			tdHtml.setLength(0);
			int startDate = addDate+i;
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			if(0!=i && "1".equals(dd)){
				dd=Integer.toString( Integer.parseInt(yyymmdd.substring(4,6))) +"."+dd;
			}
			String gl_busy_type="";
			String gl_pm_dc="";
			String gl_pm_dc_style="";
			
			String nowBgColor="@bgcolor";
			if(Integer.parseInt(frmDate.format(d1.getTime().getTime()))- Integer.parseInt(frmDate.format(drawCal.getTime().getTime()))==0){
				nowBgColor="#e3fefe";
			}
			
			tdHtml.append("<td class=\"day23\" width=\"14%\" valign=\"top\" bgcolor=\""+nowBgColor+"\"");
			tdHtml.append("	id=\"day_"+yyymmdd+"\">");
			tdHtml.append("	<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">");
			tdHtml.append("		<tbody>");
			tdHtml.append("			<tr>");
			tdHtml.append("				<td align=\"left\" valign=\"top\" height=\"100\"><b><a href=\"#\">");
			tdHtml.append("					<font color=\"green\">"+dd+"</font></a></b>");
			tdHtml.append("					<span class=\"pm_nm pms\">@pm_nm&nbsp;</span>");
			tdHtml.append("					<span class=\"pm_dc pms\" style=\"color: red; text-align: center; position: relative; float: left; width: 100%; clear: both;@pm_dc_style\">@pm_dc1&nbsp;</span>");
			
			int reservation_cnt =0; //예약수
			String for_busy_type = "";
			for(int j =0; j< list.size();j++){
				
				Map room = (Map) list.get(j);
				int pr_no = (Integer) room.get("pr_no");
				String room_nm = (String) room.get("room_nm");
				String room_type = (String) room.get("room_type");
				String room_form = (String) room.get("room_form");
				
				int busy_1_base  =   (Integer) room.get("busy_1_base");
				int busy_1_fri   =   (Integer) room.get("busy_1_fri");
				int busy_1_sat	=	(Integer) room.get("busy_1_sat");	
				
				roomsList.setLength(0);
				
				for(int k=readFast; k < list2.size();k++){
//						k=readFast;
					Map dateList = (Map) list2.get(k);
					
					String reservation_dt =  dateList.get("reservation_dt")==null?"":(String)dateList.get("reservation_dt");
					int rd_pr_no = (Integer) dateList.get("pr_no");
					int rm_no= (Integer) dateList.get("rm_no")==null?0:(Integer) dateList.get("rm_no");
					
					if(Integer.parseInt(yyymmdd)< Integer.parseInt(reservation_dt)){
						
						readFast=k-list.size();
						if(readFast<0){
							readFast=0;
						}
						break;
					}
					if(reservation_dt.equals(yyymmdd) && pr_no == rd_pr_no){
						String busy_type = (String) dateList.get("busy_type")==null?"":(String)dateList.get("busy_type");
						for_busy_type = busy_type;
						String rm_status = (String) dateList.get("rm_status")==null?"":(String)dateList.get("rm_status");
						String reservation_nm = (String) dateList.get("reservation_nm")==null?"":(String)dateList.get("reservation_nm");
						String r_phone1 = (String) dateList.get("r_phone1")==null?"":(String)dateList.get("r_phone1");
						String r_phone2 = (String) dateList.get("r_phone2")==null?"":(String)dateList.get("r_phone2");
						String r_phone3 = (String) dateList.get("r_phone3")==null?"":(String)dateList.get("r_phone3");
						int pm_dc_m =  dateList.get("pm_dc_m")==null?0:(Integer)dateList.get("pm_dc_m");
						int pm_per =  dateList.get("pm_per")==null?0:(Integer)dateList.get("pm_per");
						
						String pm_pay = dateList.get("pm_pay")==null?"":String.valueOf(dateList.get("pm_pay")) ;
						gl_pm_dc_style="margin-top:-10px;";
						if("".equals(gl_pm_dc) ){
//							if("Y".equals(pensionInfo.get("pm_dc_yn")) ){
//								if("Y".equals(pensionInfo.get("pm_nm_yn")) ){
//									gl_pm_dc+="<br/>";
//								}
//							}
							gl_pm_dc+="<br/>";
							if(!"".equals(pm_pay) && "Y".equals(pensionInfo.get("pm_dc_yn"))){
								if(pm_dc_m>0){
									gl_pm_dc+="("+"DC : "+pm_dc_m+"원할인)";
								}
								if(pm_per>0){
									gl_pm_dc+="("+"DC : "+pm_per+"% 할인)";
								}
							}	
						}
						
						if("0101".equals(busy_type)){
							gl_busy_type="비수기 주중";
						}else if("0102".equals(busy_type)){
							gl_busy_type="비수기 금요일";
						}else if("0103".equals(busy_type)){
							gl_busy_type="비수기 토요일";
						}else if("0104".equals(busy_type)){
							gl_busy_type="준수기 주중";
						}else if("0105".equals(busy_type)){
							gl_busy_type="준수기 금요일";
						}else if("0106".equals(busy_type)){
							gl_busy_type="준수기 토요일";
						}else if("0107".equals(busy_type)){
							gl_busy_type="성수기 주중";
						}else if("0108".equals(busy_type)){
							gl_busy_type="성수기 금요일";
						}else if("0109".equals(busy_type)){
							gl_busy_type="성수기 토요일";
						}else if("0110".equals(busy_type)){
							gl_busy_type="휴일";
						}else{
							
							if(7==drawCal.get(Calendar.DAY_OF_WEEK)){//토요일
								gl_busy_type="비수기 토요일";
								busy_type = "0103";
							}else	if(6==drawCal.get(Calendar.DAY_OF_WEEK)
									&& "Y".equals(friday_yn)		//금요일 사용 함일경우
									){//금요일
								gl_busy_type="비수기 금요일";
								busy_type = "0102";
							}else{//평일
								gl_busy_type="비수기 주중";
								busy_type = "0101";
							}	
						}
						if("N".equals(pensionInfo.get("pm_nm_yn")) ){
							gl_busy_type="";
						}
						if("0110".equals(busy_type)){
							roomsList.append(" ");
							//휴일일때 객실 초기화
						}else{
							roomsList.append("					<span	class=\"divDel\"><br/>");
							if("Y".equals(p_ico_yn)){
								if("F".equals(room_type)){
									roomsList.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");	
								}else if("C".equals(room_type)){
									roomsList.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								}else if("B".equals(room_type)){
									roomsList.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								}
							}
							String viewNm = room_nm;
							if("C".equals(rm_status)){
								viewNm="<span class=\"ptrend\">완료["+reservation_nm+"]</span>";
								reservation_cnt++;
							}else if("R".equals(rm_status)){
								viewNm="<span class=\"ptrstandby\">대기["+reservation_nm+"]</span>";
								reservation_cnt++;
							}
							String r_phone="";
							if(null != r_phone1 && !"".equals(r_phone1)){
								r_phone=r_phone1+"-"+r_phone2+"-"+r_phone3;
							}
							
							roomsList.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
							roomsList.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
							roomsList.append("							onmouseout=\"hideTip()\"> ");
							roomsList.append("							<a href=\"#\" id=\"a_"+pr_no+"_"+yyymmdd+"\"");
							roomsList.append("								onclick=\"goReserrvation('"+p_id+"',this,'"+pr_no+"');\" room_nm=\" "+room_nm+"\"");
							roomsList.append("								room_form=\""+room_form+"\" room_type=\""+room_type+"\" rm_status=\""+rm_status+"\" date=\""+yyymmdd+"\"");
							roomsList.append("								busy_1_base=\""+busy_1_base+"\" busy_1_fri=\""+busy_1_fri+"\" busy_1_sat=\""+busy_1_sat+"\" ");
							if(!"".equals(reservation_nm)){
								roomsList.append("								reservation_nm=\""+reservation_nm+"\" r_phone=\""+r_phone+"\" ");	
							}

							if(!"".equals(pm_pay)){
								roomsList.append("						pm_pay=\""+pm_pay+"\"");	
							}
							if(0!=rm_no){
								roomsList.append("						rm_no=\""+rm_no+"\"");
							}
							
							roomsList.append("								busy_type=\""+busy_type+"\"> "+viewNm+"</a>");
							roomsList.append("						</span>");
							roomsList.append("					</span>");
						}
						
					}
				}
//					설정 안되어있을경우 기본으로 설정합
				if("".equals(roomsList.toString()) ){
					//요금 설정해야함. 
					String busy_type = "";
					
					if(7==drawCal.get(Calendar.DAY_OF_WEEK)){//토요일
						gl_busy_type="비수기 토요일";
						busy_type = "0103";
					}else	if(6==drawCal.get(Calendar.DAY_OF_WEEK)
							&& "Y".equals(friday_yn)		//금요일 사용 함일경우
							){//금요일
						gl_busy_type="비수기 금요일";
						busy_type = "0102";
					}else{//평일
						gl_busy_type="비수기 주중";
						busy_type = "0101";
					}
					if("N".equals(pensionInfo.get("pm_nm_yn")) ){
						gl_busy_type="";
					}
					
					//기본값 설정
					roomsList.append("					<span	class=\"divDel\"><br/>");
					if("Y".equals(p_ico_yn)){
						if("F".equals(room_type)){
							roomsList.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");	
						}else if("C".equals(room_type)){
							roomsList.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						}else if("B".equals(room_type)){
							roomsList.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						}
					}
					roomsList.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
					roomsList.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
					roomsList.append("							onmouseout=\"hideTip()\"> ");
					roomsList.append("							<a href=\"#\" id=\"a_"+pr_no+"_"+yyymmdd+"\"");
					roomsList.append("								onclick=\"goReserrvation('"+p_id+"',this,'"+pr_no+"');\" room_nm=\" "+room_nm+"\"");
					roomsList.append("								room_form=\""+room_form+"\" room_type=\""+room_type+"\" rm_status=\"\" date=\""+yyymmdd+"\"");
					roomsList.append("								busy_1_base=\""+busy_1_base+"\" busy_1_fri=\""+busy_1_fri+"\" busy_1_sat=\""+busy_1_sat+"\" ");
					roomsList.append("								busy_type=\""+busy_type+"\"> "+room_nm+"</a>");
					roomsList.append("						</span>");
					roomsList.append("					</span>");
				}else{
					
				}
				//휴일일 경우 객실정보 입력안함
				if(!"0110".equals(for_busy_type)){
					tdHtml.append(roomsList.toString());	
				}
			}
			//휴일일경우 이미지로 대체
			if("0110".equals(for_busy_type)){
				tdHtml.append("<br/><table style=\"width:100%;height:100%;text-align: center\"><tr><td valign='middle'><img src=\"/usr/images/reservation.jpg\" border=\"0\" style=\"\"/></td></tr></table>");
			}
			/////


			//색지정
			if(reservation_cnt==0){//예약 없을때
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fefefe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style) );

			}else if(reservation_cnt==list.size()){//예약 모두 찬거
				textCal.append(tdHtml.toString()
						.replace("@bgcolor", "#fafc98")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style) );
			}else{//예약 조금 찬거
				textCal.append(tdHtml.toString()
						.replace("@bgcolor", "#fef0fe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style) );
			}

			textCal.append("				</td>");
			textCal.append("			</tr>");
			textCal.append("		</tbody>");
			textCal.append("	</table>");
			textCal.append("</td>");
			
			if(startDate % 7==0){
				textCal.append("</tr>");
				if(sMonthWeek==chkWeek){
					break;
				}
				textCal.append("<tr class=\"tt\" align=\"center\">");
				chkWeek++;
			}
			drawCal.add(Calendar.DATE, 1);
			
		}
			

		
		mav.addObject("txtCal",textCal.toString());
		
		
		mav.addObject("pensionInfo",pensionInfo);
		
		vo.setSb_type("brd");
		mav.addObject("brdList", service.pere100Q(vo));
		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));
		return mav;
	}
	
	/**
	 * sms 타이틀 수정하기
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere2300T(PEREVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isMember(req,res);
		
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		jsonMap.put("cnt", service.pere2300T(vo));
		mav.addObject("map", jsonMap);
		
		
		return mav;
	}
	
	
	
	
	/**
	 * 모바일 결제 처리
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere5001T(@RequestParam Map<String,Object> vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView("common/html");
		
		int[] seedKey = SEEDUtil.getSeedRoundKey(ConstValue.SeedRoundKey);
		
		if(null == vo.get("seq_code") || "" == vo.get("seq_code")){
//			throw new NoSuchRequestHandlingMethodException(req);
			System.out.println("1");
			throw new Exception("에러");
		}else{
			String seq_code = vo.get("seq_code").toString();
			try {
				SEEDUtil.getSeedDecrypt(seq_code, seedKey);	
			} catch (Exception e) {
//				throw new NoSuchRequestHandlingMethodException(req);
				System.out.println("2");
				throw new Exception("에러");
			}
		}
		
		String p_usr_nm = vo.get("usr_nm").toString();
		int p_pay = Integer.parseInt( vo.get("pay").toString());
		System.out.println("p_usr_nm : "+p_usr_nm);
		System.out.println("p_pay : "+p_pay);
		List list= service.pere5001Q(vo);
		if(null != list && list.size()>0){
			boolean chk = false;
			for(int i= 0; i< list.size();i++){
				Map map = (Map) list.get(i);
				if(map== null){
					mav.addObject("msg","N");
				}else{
					int totalPay = 0;
					String data =(String) map.get("r_info");
					
					//부가서비스 가격
					String add_svc = data.split("@")[0];
					
					String into = data.split("@")[1];
					int pay = 0;
					String room_nm="";

					for(int j=0; j<into.split(";").length;j++){

						String[] vals = into.split(";")[j].split(":");
						//입금대기자 정보(부가서비스 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...
						pay +=Integer.parseInt(vals[6]);
					}
					
					totalPay = pay+Integer.parseInt(add_svc);
					if(totalPay == p_pay){
						PEREVo vo1 = new PEREVo();
						long[] rm_nos = {0};
						rm_nos[0] = Integer.parseInt(map.get("rm_no").toString()) ;
						vo1.setRm_nos(rm_nos);
						vo1.setP_id(map.get("p_id").toString());
						service.pere700T(vo1);
						
						chk = true;
						mav.addObject("msg","Y");
						return mav;
					}else{
						
					}
				}
			}
			if(!chk){
				//return이 안되면 에러를 반환
				System.out.println("3");
				throw new Exception("에러");				
			}

		}else{
			System.out.println("4");
			throw new Exception("에러");
		}
		
		return mav;
	}
}
